int call1(int in,int one,int two) { if(in>=n) { int len=v.size()-x-x; int flg=0; for(int i=0;i<len;i++) { if(v[i]+v[i+x]+v[i+x+x]!=6) { debug(v[i],v[i+x],v[i+x+x]) flg=1; break; } } if(flg) return 1; return 0; } if(mpp[MP(one,two)]!=0) return mpp[MP(one,two)]; v.PB(1); int s1=call(one+1,two); v.pop_back(); v.PB(2); int s2=call(one,two+1); v.pop_back(); v.PB(3); int s3=call(one,two); v.pop_back(); //if(val==-1) return (s1%MOD+s2%MOD+s3%MOD)%MOD; return mpp[MP(one,two)]=(s1%MOD+s2%MOD+s3%MOD)%MOD; }
int call(int in,int val) { if(in>=n) { int len=v.size()-x-x; int flg=0; for(int i=0;i<len;i++) { if(v[i]+v[i+x]+v[i+x+x]!=6) { //debug(v[i],v[i+x],v[i+x+x]) flg=1; break; } } if(flg) return 1; return 0; } //if(val!=-1 && dp[val][in]!=-1) return dp[val][in]; v.PB(1); int s1=call(in+1,0); v.pop_back(); v.PB(2); int s2=call(in+1,1); v.pop_back(); v.PB(3); int s3=call(in+1,2); v.pop_back(); if(val==-1) return (s1%MOD+s2%MOD+s3%MOD)%MOD; return dp[val][in]=(s1%MOD+s2%MOD+s3%MOD)%MOD; }
void print(int in, int make) { //debug(in,make,pri[in][make]) if(in>=n) { //debug("vi",v.size(),make) if(make==0) { tc++; call(0,0); } return; } int kk = pri[in][make]; if(kk==3) { v.PB(a[in]); print(in+1,make-a[in]); v.pop_back(); print(in+1, make); } else if(kk==1) { print(in+1, make); } else { v.PB(a[in]); print(in+1, make-a[in]); v.pop_back(); } }
int main() { //READ("in.txt"); //WRITE("out.txt"); int t; getI(t); for(int ci=1;ci<=t;ci++) { v.clear(); SET(dp); CLR(pri); getI(totLen); totLen*=100; len=0; int x; while(getI(x) && x) { //x/=100; v.PB(x); len++; } cout << call(0,0,0) <<endl; print(0,0,0); if(ci<t) printf("\n"); } return 0; }
int main() { //READ("in.txt"); //WRITE("out.txt"); int tc; getI(tc); for(int i=1;;i++) { int k=i*i; if(k>10000) break; v.PB(k); //debug(k) } len=v.size(); debug(len) SET(dp); for(int ci=1;ci<=tc;ci++) { int n; getI(n); cout << call(n) << endl; } return 0; }
void go (int n, int k) { if (!n) { par.PB(cur); sort(ALL(par.back())); return; } for (int i=k; i>=1; i--) { if (i > n) continue; cur.PB(i); go(n-i, i); cur.pop_back(); } }
void solve(int tt){ int i,j; scanf("%d%d",&i,&j); nodes.clear(); while(i>=1){ nodes.PB(i); i/=2; } int d=0; while(j>=1){ int val=srch(j); if(val >= 0){ printf("%d\n",d+val); return; } j/=2; d++; } }
void call(int in) { if(in>=n && v.size()==6) { for(int i=0;i<6;i++) { if(i) printf(" "); printf("%d",v[i]); } printf("\n"); return; } if(in>=n) return; if(v.size()<6) { v.PB(a[in]); call(in+1); v.pop_back(); } call(in+1); }
int main() { READ("inF.in"); WRITE("out.txt"); int t; getI(t); for(int ci=1;ci<=t;ci++) { //SET(dp); int n; getI(n); /// // cout << n << endl; /// v.clear(); maxt=0; for(int i=0;i<n;i++) { int k; getI(k); v.PB(k); /// // cout << k << " "; /// maxt=max(maxt,k); } /// // printf("\n"); /// printf("Case #%d: %d\n",ci,call(0,maxt)); /// // printf("\n"); /// } return 0; }
int main() { prime = vb(N, true); prime[0]=prime[1] = false; for (int i=0; i*i<N; i++) { if (!prime[i]) continue; for (int j=i*i; j<N; j+=i) prime[j] = false; } REP(i,N) if (prime[i]) primes.PB(i); ll cur=100; // keeping track of where we are ll n=5; ll gn=13; while (true) { ll g = gcd(n,gn); if (n==cur+1) { cout << gn << endl; if (cur==STOP) break; cur *= 10; } else if (g > 1) { n++; gn += g; } else { if (n > STOP) assert(false); ll diff = gn-n; vector<pii> factors = factor(diff); ll leap = oo; FOREACH(it,factors) { leap = min(leap, it->first - gn%it->first); } if (n + leap > cur) { cout << gn + (cur-n) + 1 << endl; if (cur==STOP) break; cur *= 10; } n+=leap; gn+=leap; } }
int call(int time,int mx) { // if(dp[time][mx]!=-1) return dp[time][mx]; if(time>maxt) return INF; sort(ALLR(v)); if(v[0]<=0) {debug(time);return time;} int p1=INF,p2=INF; for(int i=0;i<v.size();i++) { v[i]--; } p1=call(time+1,v[0]-1); for(int i=0;i<v.size();i++) { v[i]++; } vi temp; temp=v; int i=v[0]; int cnt=0; if(i%2==0) { int vag=i/2; while(v[0]==i) { v.erase(v.begin()); v.PB(vag); v.PB(vag); time++; cnt++; } } else if(i%2==1) { int vag=i/2; while(v[0]==i) { v.erase(v.begin()); v.PB(vag); v.PB(vag+1); time++; cnt++; } } sort(ALLR(v)); p2=call(time,v[0]); v=vi(); v=temp; // vi :: iterator it; // if(i%2==0) // { // int vag=i/2; // while(cnt--) // { // it=find(ALL(v),vag); // v.erase(it); // it=find(ALL(v),vag); // v.erase(it); // v.PB(i); // } // } return (min(p1,p2)); }
int main() { // READ("in.txt"); //WRITE("out.txt"); int t; getI(t); for(int ci=1;ci<=t;ci++) { good.clear(); bad.clear(); ugly.clear(); int n; getI(n); for(int i=0;i<n;i++) { int x; string st; // scanf("%d %s",&x,st.c_str()); cin >> x >> st; // debug(x,st) if(st=="Good") { good.PB(x); } else if(st=="Bad") { bad.PB(x); } else { ugly.PB(x); } } int flg=1; if(good.size()==bad.size() && good.size()==ugly.size()) { int len=good.size(); int in=0; sort(ALL(good)); sort(ALL(bad)); sort(ALL(ugly)); for(int in=0;in<len;in++) { if(bad[in]<good[in] || ugly[in]<good[in]) { flg=0; break; } } } else { // debug(good) flg=0; } if(flg) printf("Case %d: GBU\n",ci); else printf("Case %d: Undefined\n",ci); } return 0; }
vi mul(vi v,int a){ int l=SZ(v); for(int i=0;i<l;++i)v.PB(a*v[i]); return v; }