Ejemplo n.º 1
0
 bool isInterleave(string s1, string s2, string s3) {
     if (s3.size() != s1.size() + s2.size()) {
         return false;
     }
     
     if (s1.size() == 0) {
         return s2 == s3;
     } else if (s2.size() == 0) {
         return s1 == s3;
     }
     
     int preS1 = getMaxPrefix(s1, s3);
     int preS2 = getMaxPrefix(s2, s3);
     bool ret = false;
     
     for (int len = preS1; len >= 1; len--) {
         ret = ret || isInterleave(s1.substr(len), s2, s3.substr(len));
         if (ret) {
             return true;
         }
     }
     
     for (int len = preS2; len >= 1; len--) {
         ret = ret || isInterleave(s1, s2.substr(len), s3.substr(len));
         if (ret) {
             return true;
         }
     }
     
     return ret;
 }
Ejemplo n.º 2
0
 bool isInterleave(int i, int j){
     int k = i + j;
     pair<int, int> ij = make_pair(i, j);
     if (mp.count(ij) > 0){
         return mp[ij];
     }
     
     if (i == n1 && j == n2 && k == n3){
         return mp[ij] = true;
     }
     char c1 = (i < n1) ? s1[i] : '\0';
     char c2 = (j < n2) ? s2[j] : '\0';
     char c3 = (k < n3) ? s3[k] : '\0';
     if (c1 == c3 && c2 == c3){
         return mp[ij] = isInterleave(i, j+1) || isInterleave(i+1, j);
     }
     else if (c1 == c3 && c2 != c3){
         return mp[ij] = isInterleave(i+1, j);
     }
     else if (c1 != c3 && c2 == c3){
         return mp[ij] = isInterleave(i, j+1);
     }
     else {
         return mp[ij] = false;
     }
 }
Ejemplo n.º 3
0
    bool isInterleave(const string &s1, int i, const string &s2, int j, const string &s3, int k){
		// if(i+j != k)
			// return false;
		if(i<0 && j<0 && k<0)
			return true;
		
		if(i>=0 && k>=0 && s1[i]==s3[k] && isInterleave(s1, i-1, s2, j, s3, k-1))
			return true;
			
		if(j>=0 && k>=0 && s2[j]==s3[k] && isInterleave(s1, i, s2, j-1, s3, k-1))
			return true;
			
		return false;
	}
Ejemplo n.º 4
0
bool isInterleave(char* s1, char* s2, char* s3) {
     // Base Case: If all strings are empty 
    if (!(*s1 || *s2 || *s3)) 
        return true; 
  
    // If C is empty and any of the two strings is not empty 
    if (*s3 == '\0') 
        return false; 
  
    // If any of the above mentioned two possibilities is true, 
    // then return true, otherwise false 
    return ( (*s3 == *s1) && isInterleave(s1+1, s2, s3+1)) 
           || ((*s3 == *s2) && isInterleave(s1, s2+1, s3+1));
}
Ejemplo n.º 5
0
    bool isInterleave(const string &s1, int i, const string &s2, int j, const string &s3, int k){
		// if(i+j != k)
			// return false;
		if(i>=s1.size() && j>=s2.size() && k>=s3.size())
			return true;
		
		if(i<s1.size() && k<s3.size() && s1[i]==s3[k] && isInterleave(s1, i+1, s2, j, s3, k+1))
			return true;
			
		if(j<s2.size() && k<s3.size() && s2[j]==s3[k] && isInterleave(s1, i, s2, j+1, s3, k+1))
			return true;
			
		return false;
	}
Ejemplo n.º 6
0
	bool isInterleave(string s1, string s2, string s3) {
		// Start typing your C/C++ solution below
		// DO NOT write int main() function    
		if(s1.size()+s2.size() != s3.size())
			return false;
		if(!(s1.size() || s2.size() || s3.size()))
			return true;
		bool res1,res2;
		if(s1.size() == 0||s1.size() > 0 && s1[0] != s3[0])
			res1 = false;
		else
			res1 = isInterleave(s1.substr(1), s2, s3.substr(1));
		if(s2.size() == 0||s2.size() > 0 && s2[0] != s3[0])
			res2 = false;
		else
			res2 = isInterleave(s1, s2.substr(1), s3.substr(1));
		return res1||res2;
	}
Ejemplo n.º 7
0
int main(int argc, char **argv)
{
    if (argc != 4) {
        fprintf(stderr, "Usage: ./test s1 s2 s3\n");
        exit(-1);
    }
    printf("%s\n", isInterleave(argv[1], argv[2], argv[3]) ? "true" : "false");
    return 0;
}
Ejemplo n.º 8
0
 bool isInterleave(string s1, string s2, string s3) {
     if(s1.empty() && s2.empty() && s3.empty()) {
         return true;
     }
     if(cache.count(s1+"#"+s2) || s1.size() + s2.size() != s3.size()) {
         return false;
     }
     if(!s1.empty() && !s3.empty() && s1[0]==s3[0]) {
         if(isInterleave(s1.substr(1), s2, s3.substr(1))) {
             return true;
         } 
     }
     if(!s2.empty() && !s3.empty() && s2[0] == s3[0]) {
         if(isInterleave(s1, s2.substr(1), s3.substr(1))) {
             return true;
         }
     }
     
     cache.insert(s1+"#"+s2);
     return false;
 }
Ejemplo n.º 9
0
 bool isInterleave(string s1, string s2, string s3) {
     if (s3.size() != s1.size() +s2.size()) return false;
     this->s1 = s1.c_str();
     this->s2 = s2.c_str();
     int m = s1.size() + 1;
     n = s2.size() +1;
     int k = m*n;
     b.resize(k);
     bool r = isInterleave(this->s1, this->s2, s3.c_str());
     b.clear();
     return r;
 }
Ejemplo n.º 10
0
	bool isInterleave(string s1, string s2, string s3)
	{
		if(s1.empty())
			return s2==s3;
			
		if(s2.empty())
			return s1==s3;
		
		if(s3.empty())
			return s1.empty() && s2.empty();
			
		char ch1 = s1[s1.size()-1];
		char ch2 = s2[s2.size()-1];
		char ch3 = s3[s3.size()-1];
		
		if(ch3 == ch1 && isInterleave(s1.substr(0, s1.size()-1), s2, s3.substr(0, s3.size()-1)))
			return true;
		if(ch3 == ch2 && isInterleave(s1, s2.substr(0, s2.size()-1), s3.substr(0, s3.size()-1)))
			return true;
			
		return false;
	}
Ejemplo n.º 11
0
 bool isInterleave(string s1, string s2, string s3) {
    this->s1 = s1;
    this->s2 = s2;
    this->s3 = s3;
    n1 = s1.length();
    n2 = s2.length();
    n3 = s3.length();
    if (n1 + n2 != n3){
        return false;
    }
    return isInterleave(0, 0);
    
 }
Ejemplo n.º 12
0
 bool isInterleave(string s1, string s2, string s3, unordered_map<string, bool> & m) {
     if (s3.size() != s1.size() + s2.size()) {
         return false;
     }
     
     if (s1.size() == 0) {
         return s2 == s3;
     } else if (s2.size() == 0) {
         return s1 == s3;
     }
     
     if (m.find(s3) != m.end() && m[s3] == true) {
         return true;
     }
     
     int preS1 = getMaxPrefix(s1, s3);
     int preS2 = getMaxPrefix(s2, s3);
     bool ret = false;
     
     for (int len = preS1; len >= 1; len--) {
         ret = ret || isInterleave(s1.substr(len), s2, s3.substr(len), m);
         if (ret) {
             m[s3] = true;
             return true;
         }
     }
     
     for (int len = preS2; len >= 1; len--) {
         ret = ret || isInterleave(s1, s2.substr(len), s3.substr(len), m);
         if (ret) {
             m[s3] = true;
             return true;
         }
     }
     
     m[s3] = ret;
     return ret;
 }
Ejemplo n.º 13
0
    bool isInterleave(string s1, string s2, string s3){
		if(s1.empty())
			return s2 == s3;
		if(s2.empty())
			return s1 == s3;
	
		int m = s1.size();
		int n = s2. size();
		int o = s3.size();
		if(m+n != o)
			return false;
			
		return isInterleave(s1, m-1, s2, n-1, s3, o-1);
	}
Ejemplo n.º 14
0
 bool isInterleave(string s1, string s2, string s3, unordered_map<pair<string, string>, bool> & m) {
     if (s3.size() != s1.size() + s2.size()) {
         return false;
     }
     
     if (s1.size() == 0) {
         return s2 == s3;
     } else if (s2.size() == 0) {
         return s1 == s3;
     }
     
     pair<string, string> p = make_pair(s1, s2);
     if (m.find(p) != m.end()) {
         return m[p];
     }
     
     int preS1 = getMaxPrefix(s1, s3);
     int preS2 = getMaxPrefix(s2, s3);
     bool ret = false;
     
     for (int len = preS1; len >= 1; len--) {
         ret = ret || isInterleave(s1.substr(len), s2, s3.substr(len));
         if (ret) {
             return true;
         }
     }
     
     for (int len = preS2; len >= 1; len--) {
         ret = ret || isInterleave(s1, s2.substr(len), s3.substr(len));
         if (ret) {
             return true;
         }
     }
     
     m[p] = ret;
     return ret;
 }
Ejemplo n.º 15
0
 bool isInterleave(const char* s1, const char* s2, const char* s3) {
     int i = s1 - this->s1;
     int j = s2 - this->s2;
     int k = i*n + j;
     if (b[k]) return false; 
     while (true) {
         if (*s3=='\0') {return true;}
         if (*s1!=*s2) {
             if (*s1==*s3) {++s1;++s3;continue;}
             if (*s2==*s3) {++s2;++s3;continue;}
             break;
         } else {
             if (*s1 != *s3) break;
             if (isInterleave(s1+1,s2,s3+1)) {return true;}
             ++s2;++s3;continue;
         }
     }
     b[k] = true;
     return false;
 }
Ejemplo n.º 16
0
bool isInterleave(char* s1, char* s2, char* s3){
    int s1length=strlen(s1);
    int s2length=strlen(s2);
    int s3length=strlen(s3);
    if(s1length + s2length != s3length ) 
        return false;
    if(s1length < s2length ) 
        return isInterleave(s2, s1, s3);
    bool f[s2length + 1];
    memset(f,1,sizeof(f));
    for(int j = 1; j <= s2length; ++j){
        f[j] = f[j - 1] && s2[j - 1] == s3[j - 1];
    }
    for(int i = 1; i <= s1length; ++i) {
        f[0] = f[0] && s1[i - 1] == s3[i - 1];
        for(int j = 1; j <= s2length; ++j) {
            f[j] = (f[j] && s1[i - 1] == s3[i + j - 1]) || (f[j - 1] && s2[j - 1] == s3[i + j - 1]);
        }
    }
    return f[s2length];
}
Ejemplo n.º 17
0
static int Ti3026_init(struct matrox_fb_info *minfo, struct my_timming *m)
{
	u_int8_t muxctrl = isInterleave(minfo) ? TVP3026_XMUXCTRL_MEMORY_64BIT : TVP3026_XMUXCTRL_MEMORY_32BIT;
	struct matrox_hw_state *hw = &minfo->hw;

	DBG(__func__)

	memcpy(hw->DACreg, MGADACbpp32, sizeof(hw->DACreg));
	switch (minfo->fbcon.var.bits_per_pixel) {
		case 4:	hw->DACreg[POS3026_XLATCHCTRL] = TVP3026_XLATCHCTRL_16_1;	/* or _8_1, they are same */
			hw->DACreg[POS3026_XTRUECOLORCTRL] = TVP3026_XTRUECOLORCTRL_PSEUDOCOLOR;
			hw->DACreg[POS3026_XMUXCTRL] = muxctrl | TVP3026_XMUXCTRL_PIXEL_4BIT;
			hw->DACreg[POS3026_XCLKCTRL] = TVP3026_XCLKCTRL_SRC_PLL | TVP3026_XCLKCTRL_DIV8;
			hw->DACreg[POS3026_XMISCCTRL] = TVP3026_XMISCCTRL_DAC_PUP | TVP3026_XMISCCTRL_DAC_8BIT | TVP3026_XMISCCTRL_PSEL_DIS | TVP3026_XMISCCTRL_PSEL_LOW;
			break;
		case 8: hw->DACreg[POS3026_XLATCHCTRL] = TVP3026_XLATCHCTRL_8_1;	/* or _4_1, they are same */
			hw->DACreg[POS3026_XTRUECOLORCTRL] = TVP3026_XTRUECOLORCTRL_PSEUDOCOLOR;
			hw->DACreg[POS3026_XMUXCTRL] = muxctrl | TVP3026_XMUXCTRL_PIXEL_8BIT;
			hw->DACreg[POS3026_XCLKCTRL] = TVP3026_XCLKCTRL_SRC_PLL | TVP3026_XCLKCTRL_DIV4;
			hw->DACreg[POS3026_XMISCCTRL] = TVP3026_XMISCCTRL_DAC_PUP | TVP3026_XMISCCTRL_DAC_8BIT | TVP3026_XMISCCTRL_PSEL_DIS | TVP3026_XMISCCTRL_PSEL_LOW;
			break;
		case 16:
			/* XLATCHCTRL should be _4_1 / _2_1... Why is not? (_2_1 is used every time) */
			hw->DACreg[POS3026_XTRUECOLORCTRL] = (minfo->fbcon.var.green.length == 5) ? (TVP3026_XTRUECOLORCTRL_DIRECTCOLOR | TVP3026_XTRUECOLORCTRL_ORGB_1555) : (TVP3026_XTRUECOLORCTRL_DIRECTCOLOR | TVP3026_XTRUECOLORCTRL_RGB_565);
			hw->DACreg[POS3026_XMUXCTRL] = muxctrl | TVP3026_XMUXCTRL_PIXEL_16BIT;
			hw->DACreg[POS3026_XCLKCTRL] = TVP3026_XCLKCTRL_SRC_PLL | TVP3026_XCLKCTRL_DIV2;
			break;
		case 24:
			/* XLATCHCTRL is: for (A) use _4_3 (?_8_3 is same? TBD), for (B) it is set in setpclk */
			hw->DACreg[POS3026_XTRUECOLORCTRL] = TVP3026_XTRUECOLORCTRL_DIRECTCOLOR | TVP3026_XTRUECOLORCTRL_RGB_888;
			hw->DACreg[POS3026_XMUXCTRL] = muxctrl | TVP3026_XMUXCTRL_PIXEL_32BIT;
			hw->DACreg[POS3026_XCLKCTRL] = TVP3026_XCLKCTRL_SRC_PLL | TVP3026_XCLKCTRL_DIV4;
			break;
		case 32:
			/* XLATCHCTRL should be _2_1 / _1_1... Why is not? (_2_1 is used every time) */
			hw->DACreg[POS3026_XMUXCTRL] = muxctrl | TVP3026_XMUXCTRL_PIXEL_32BIT;
			break;
		default:
			return 1;	/* TODO: failed */
	}
	if (matroxfb_vgaHWinit(minfo, m)) return 1;

	/* set SYNC */
	hw->MiscOutReg = 0xCB;
	if (m->sync & FB_SYNC_HOR_HIGH_ACT)
		hw->DACreg[POS3026_XGENCTRL] |= TVP3026_XGENCTRL_HSYNC_NEG;
	if (m->sync & FB_SYNC_VERT_HIGH_ACT)
		hw->DACreg[POS3026_XGENCTRL] |= TVP3026_XGENCTRL_VSYNC_NEG;
	if (m->sync & FB_SYNC_ON_GREEN)
		hw->DACreg[POS3026_XGENCTRL] |= TVP3026_XGENCTRL_SYNC_ON_GREEN;

	/* set DELAY */
	if (minfo->video.len < 0x400000)
		hw->CRTCEXT[3] |= 0x08;
	else if (minfo->video.len > 0x400000)
		hw->CRTCEXT[3] |= 0x10;

	/* set HWCURSOR */
	if (m->interlaced) {
		hw->DACreg[POS3026_XCURCTRL] |= TVP3026_XCURCTRL_INTERLACED;
	}
	if (m->HTotal >= 1536)
		hw->DACreg[POS3026_XCURCTRL] |= TVP3026_XCURCTRL_BLANK4096;

	/* set interleaving */
	hw->MXoptionReg &= ~0x00001000;
	if (isInterleave(minfo)) hw->MXoptionReg |= 0x00001000;

	/* set DAC */
	Ti3026_setpclk(minfo, m->pixclock);
	return 0;
}
Ejemplo n.º 18
0
static int Ti3026_setpclk(struct matrox_fb_info *minfo, int clk)
{
	unsigned int f_pll;
	unsigned int pixfeed, pixin, pixpost;
	struct matrox_hw_state *hw = &minfo->hw;

	DBG(__func__)

	f_pll = Ti3026_calcclock(minfo, clk, minfo->max_pixel_clock, &pixin, &pixfeed, &pixpost);

	hw->DACclk[0] = pixin | 0xC0;
	hw->DACclk[1] = pixfeed;
	hw->DACclk[2] = pixpost | 0xB0;

	{
		unsigned int loopfeed, loopin, looppost, loopdiv, z;
		unsigned int Bpp;

		Bpp = minfo->curr.final_bppShift;

		if (minfo->fbcon.var.bits_per_pixel == 24) {
			loopfeed = 3;		/* set lm to any possible value */
			loopin = 3 * 32 / Bpp;
		} else {
			loopfeed = 4;
			loopin = 4 * 32 / Bpp;
		}
		z = (110000 * loopin) / (f_pll * loopfeed);
		loopdiv = 0; /* div 2 */
		if (z < 2)
			looppost = 0;
		else if (z < 4)
			looppost = 1;
		else if (z < 8)
			looppost = 2;
		else {
			looppost = 3;
			loopdiv = z/16;
		}
		if (minfo->fbcon.var.bits_per_pixel == 24) {
			hw->DACclk[3] = ((65 - loopin) & 0x3F) | 0xC0;
			hw->DACclk[4] = (65 - loopfeed) | 0x80;
			if (minfo->accel.ramdac_rev > 0x20) {
				if (isInterleave(minfo))
					hw->DACreg[POS3026_XLATCHCTRL] = TVP3026B_XLATCHCTRL_8_3;
				else {
					hw->DACclk[4] &= ~0xC0;
					hw->DACreg[POS3026_XLATCHCTRL] = TVP3026B_XLATCHCTRL_4_3;
				}
			} else {
				if (isInterleave(minfo))
					;	/* default... */
				else {
					hw->DACclk[4] ^= 0xC0;	/* change from 0x80 to 0x40 */
					hw->DACreg[POS3026_XLATCHCTRL] = TVP3026A_XLATCHCTRL_4_3;
				}
			}
			hw->DACclk[5] = looppost | 0xF8;
			if (minfo->devflags.mga_24bpp_fix)
				hw->DACclk[5] ^= 0x40;
		} else {
			hw->DACclk[3] = ((65 - loopin) & 0x3F) | 0xC0;
			hw->DACclk[4] = 65 - loopfeed;
			hw->DACclk[5] = looppost | 0xF0;
		}
		hw->DACreg[POS3026_XMEMPLLCTRL] = loopdiv | TVP3026_XMEMPLLCTRL_MCLK_MCLKPLL | TVP3026_XMEMPLLCTRL_RCLK_LOOPPLL;
	}
	return 0;
}
Ejemplo n.º 19
0
int main(int argc, const char* argv[])
{
	cout << isInterleave("a", "b" , "ab") << endl;
	return 0;
}
Ejemplo n.º 20
0
 bool isInterleave(string s1, string s2, string s3) {
     unordered_map<pair<string, string>, bool> m;
     return isInterleave(s1, s2, s3, m);
 }