/* ID: bbezxcy1 PROG: prefix LANG: C++ */ #include<fstream> #include<iostream> #include<cstring> #include<cstdio> using namespace std; char cha[203][15],str[200005]; int len[203]; bool dp[200005]; ifstream fin("prefix.in"); ofstream fout("prefix.out"); bool check(int loc,int a) { int j=len[a]-1; for(int i=loc;i>loc-len[a];i--,j--) { if(str[i]!=cha[a][j]) { return 0; } } return 1; } int main() { int n,i,j,k,ans,b,c; char buff[100]; while(fin>>cha[0]) { n=1; ans=0; len[0]=strlen(cha[0]); while(fin>>cha[n]) { if(cha[n][0]=='.') { break; } len[n]=strlen(cha[n]); n++; } fin>>str+1; while(fin>>buff) { strcat(str+1,buff); } // while(fin>>str+l) // { // l=strlen(str+1); // } memset(dp,0,sizeof(dp)); dp[0]=1; int l=strlen(str+1); // cout<<l<<endl; // cout<<n<<endl; for(i=1;i<=l;i++) { for(j=0;j<n;j++) { if(len[j]<=i&&dp[i-len[j]]==1) { // cout<<i<<" "<<j<<endl; if(check(i,j)) { ans=i; dp[i]=1; //cout<<i<<" fuck "<<j<<endl; } } } } fout<<ans<<endl; } return 0; }
/* ID: bbezxcy1 PROG: nocows LANG: C++ */ #include<iostream> #include<cstring> #include<fstream> #include<cstdio> using namespace std; ifstream fin("nocows.in"); ofstream fout("nocows.out"); int dp[300][300]; int main() { int n,k,i,j,m; while(fin>>n>>m) { memset(dp,0,sizeof(dp)); for(i=0;i<300;i++)dp[1][i]=1; for(i=3;i<=n;i++) { for(j=2;j<=m;j++) { for(k=1;k<=i-2;k++) { dp[i][j]+=dp[k][j-1]*dp[i-k-1][j-1]; dp[i][j]%=9901; } } } fout<<(dp[n][m]-dp[n][m-1]+9901)%9901<<endl; } return 0; }
/*
ID: bbezxcy1 PROG: zerosum LANG: C++ */ #include<iostream> #include<fstream> #include<stdio.h> using namespace std; ifstream fin("zerosum.in"); ofstream fout("zerosum.out"); int n; int num; char opera[20]; void print(){ int i; for(i=1;i<n;i++) fout<<i<<opera[i]; //printf("%d%c",i,opera[i]); fout<<n<<endl; } void dfs(int sum,int step,int bef){ if(step==n){ if(sum==0){ num++; if(num<=20){ print(); } } } else{ int next; opera[step]=' '; if(step<9) next=bef*10+step+1; else next=bef*100+step+1; int i=step-1; while(opera[i]==' '&&i>=0)i--; if(opera[i]=='+') dfs(sum+next-bef,step+1,next); if(opera[i]=='-') dfs(sum-next+bef,step+1,next); opera[step]='+'; next=step+1; dfs(sum+next,step+1,next); opera[step]='-'; next=step+1; dfs(sum-next,step+1,next); } } int main(){ fin>>n; num=0; opera[0]='+'; dfs(1,1,1); return 0; }
/*
ID: bbezxcy1 LANG: C++ PROG: money */ #include<cstdio> #include<iostream> #include<cstring> #include<fstream> using namespace std; ifstream fin("money.in"); ofstream fout("money.out"); long long dp[10001]; int v,n,t; int main() { fin>>v>>n; dp[0]=1; for (int i=1;i<=v;++i) { fin>>t; for (int j=t;j<=n;++j) dp[j]+=dp[j-t]; } fout<<dp[n]<<endl; return 0; }
/*
ID: bbezxcy1 PROG: concom LANG: C++ */ #include<iostream> #include<fstream> #include<cstring> #include<cstdio> using namespace std; const int nMax=110; const int mMax=300000; int ctrl[110]; class edge{ public: int u,v,nex,val; };edge e[mMax]; int k,head[nMax]; void addedge(int a,int b,int c){ // cout<<a<<" add "<<b<<" "<<c<<endl; e[k].u=a; e[k].v=b; e[k].val=c; e[k].nex=head[a]; head[a]=k;k++; } int n; bool vis[110]; void dfs(int loc){ // cout<<loc<<endl; int i; vis[loc]=1; for(i=head[loc];i;i=e[i].nex){ int v=e[i].v; if(vis[v])continue; ctrl[v]+=e[i].val; } for(i=head[loc];i;i=e[i].nex){ int v=e[i].v; if(vis[v])continue; if(ctrl[v]>50){ dfs(v); } } } ifstream fin("concom.in"); ofstream fout("concom.out"); int main() { int i,j,a,b,c; while(fin>>n) { k=1; memset(head,0,sizeof(head)); for(i=0;i<n;i++) { fin>>a>>b>>c; addedge(a,b,c); } for(i=1;i<=100;i++) { memset(vis,0,sizeof(vis)); memset(ctrl,0,sizeof(ctrl)); vis[i]=1; dfs(i); for(j=1;j<=100;j++) { if(j==i)continue; if(vis[j]) { fout<<i<<" "<<j<<endl; } } } } return 0; }