Reprinted please indicate the source, thank you http://blog.csdn.net/acm_cxlove/article/details/7854526
By --- cxlove
Slow hands ~~~~
255pt
The complexity of 50 ^ 4 is okay.
Or you can pre-process the number of 1 rows and the number of 1 rows in each column, and then enumerate to remove a column in a row. Preprocessing of 50 ^ 2 and enumeration of 50 ^ 2
500pt: 01 string, which consists of at least several parts. Each part is a power of 5 and cannot contain leading 0
DP, DP [I] [J] indicates the first I character, and the minimum segmentation at the J part
Is to enumerate the middle position K, and then determine whether the power from K to J is 5 and whether the DP [I] [k] is reachable
class CuttingBitString{public:int getmin(string S){int dp[55][55];int n=S.size();for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) dp[i][j]=99999;for(int i=0;i<=n;i++) dp[i][0]=0; for(int i=1;i<=n;i++){for(int j=0;j<i;j++){dp[i][j]=min(dp[i][j],dp[i-1][j]);if(S[j]=='0') continue;LL tmp=0;for(int k=j+1;k<=i;k++)tmp=((LL)tmp<<1)+(S[k-1]=='1');bool flag=true;while(1){if(tmp==1) break;if(tmp%5) {flag=false;break;}tmp/=5;}if(flag)dp[i][i]=min(dp[i][i],dp[i-1][j]+1);}}cout<<dp[n][n]<<endl;return dp[n][n]>n?-1:dp[n][n];}};
955pt:
DP: C [I] [J] indicates the number of combinations, DP [I] [J] indicates the I position, where J pits are placed, and how many conditions are not met.
DP [I] [J] = DP [I-3] [J] + dp [I-3] [J-1] + dp [I-2] [J-1];
class MuddyRoad2{public:int theCount(int N, int muddyCount){int dp[600][600],c[600][600];for(int i=0;i<=N;i++){c[i][0]=c[i][i]=1;for(int j=1;j<i;j++)c[i][j]=(c[i-1][j]+c[i-1][j-1])%MOD;}memset(dp,0,sizeof(dp));memset(dp,0,sizeof(dp));dp[1][0]=1;dp[2][0]=1;dp[3][1]=1;for(int i=4;i<=N;i++)for(int j=0;j<=muddyCount&&j<=i-2;j++){dp[i][j]=0;if(j)dp[i][j]=(dp[i][j]+dp[i-3][j-1]+dp[i-2][j-1])%MOD;dp[i][j]=(dp[i-3][j]+dp[i][j])%MOD;}cout<<dp[4][1]<<endl;return (c[N-2][muddyCount]-dp[N][muddyCount]+MOD)%MOD;}};