标签:覆盖 php enter sizeof printf ring iostream include gre
40%的数据满足:1<=n<=10 100%的数据满足:1<=n<=50
设f[i][j]表示区间i到j的答案
1 #include<iostream> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cstdio> 5 #include<cmath> 6 #include<algorithm> 7 using namespace std; 8 int n; 9 char s[100]; 10 int f[55][55]; 11 int main(){ 12 memset(f,97,sizeof(f)); 13 scanf("%s",s+1); 14 n=strlen(s+1); 15 for(int i=1;i<=n;i++) f[i][i]=1; 16 for(int j=1;j<=n;j++){ 17 for(int i=1;i+j<=n;i++){ 18 if(s[i]==s[i+j]) f[i][i+j]=min(f[i+1][i+j],f[i][i+j-1]); 19 else for(int k=i;k<i+j;k++) f[i][i+j]=min(f[i][k]+f[k+1][i+j],f[i][i+j]); 20 } 21 } 22 printf("%d",f[1][n]); 23 }
[BZOJ1260][CQOI2007]涂色paint 区间dp
标签:覆盖 php enter sizeof printf ring iostream include gre
原文地址:http://www.cnblogs.com/wls001/p/7608663.html