标签:printf http img ios col blog pac 技术分享 std
这题是一道状压DP,暂时还不是很懂.
#include<cstdio> #include<cstring> #include<iostream> using namespace std; const int LENM=1010,N=11,M=1e9+7; char s[N]; int n,m,u,ind[200],f[LENM][1<<10],g[N],ans[N],gg[N],num1[1<<10],ff[1<<10][5]; int main(){ scanf("%s%d",s+1,&m); n=strlen(s+1); u=1<<n; f[0][0]=1; ind[‘A‘]=1; ind[‘C‘]=2; ind[‘G‘]=3; ind[‘T‘]=4; for (int i=1; i<=n; i++) s[i]=ind[s[i]]; for (int i=0; i<u; i++){ for (int k=1; k<=n; k++) g[k]=(1&(i>>k-1))+g[k-1]; for (int j=1; j<=4; j++){ int res=0; for (int k=1; k<=n; k++){ gg[k]=max(max(g[k-1]+(s[k]==j),gg[k-1]),g[k]); res|=(gg[k]-gg[k-1])<<k-1; } ff[i][j]=res; } } for (int i=0; i<m; i++) for (int j=0; j<u; j++) if (f[i][j]) for (int k=1; k<=4; k++) (f[i+1][ff[j][k]]+=f[i][j])%=M; for (int i=0; i<u; i++){ if (i) num1[i]=num1[i-1&i]+1; (ans[num1[i]]+=f[m][i])%=M; } for (int i=0; i<=n; i++) printf("%d\n",ans[i]); }
一篇好的博客http://blog.csdn.net/HOWARLI/article/details/69487024
标签:printf http img ios col blog pac 技术分享 std
原文地址:http://www.cnblogs.com/Yuhuger/p/7570166.html