BZOJ 1566: [NOI2009]管道取珠 另类DP
2017-06-23 20:48
351 查看
题目:戳这里
题解:比较神的想法,因为最后答案是所有数的平方,那么我们就可以将问题转化一下,变成俩个人取数,两人拿出的结果相同的方案书目,YY一下就能证明这个转化的正确性,这就很好办了,瞎DP一下就行了。
题解:比较神的想法,因为最后答案是所有数的平方,那么我们就可以将问题转化一下,变成俩个人取数,两人拿出的结果相同的方案书目,YY一下就能证明这个转化的正确性,这就很好办了,瞎DP一下就行了。
#include<cstdio> #include<cstdlib> #include<ctime> #include<cmath> #include<cstring> #include<string> #include<algorithm> #include<iostream> #include<iomanip> using namespace std; char s1[600]; char s2[600]; int f[502][502][502]; const int mod=1024523; int main() { int n,m; scanf("%d%d",&n,&m); scanf("%s",s1+1); scanf("%s",s2+1); for(int i=1;i*2<=n;i++) swap(s1[i],s1[n-i+1]); for(int j=1;j*2<=m;j++) swap(s2[j],s2[m-j+1]); s1[n+1]='*'; s2[m+1]='^'; f[0][0][0]=1; for(int i=0;i<=n+m;i++) for(int j=0;j<=n && j<=i;j++) for(int k=0;k<=n && k<=i;k++) { int o1=j; int o2=i-j; int t1=k; int t2=i-k; if(o2>m || t2>m) continue; if(s1[o1+1]==s1[t1+1]) (f[o1+1][o2][t1+1]+=f[o1][o2][t1])%=mod; if(s2[o2+1]==s2[t2+1]) (f[o1][o2+1][t1]+=f[o1][o2][t1])%=mod; if(s1[o1+1]==s2[t2+1]) (f[o1+1][o2][t1]+=f[o1][o2][t1])%=mod; if(s2[o2+1]==s1[t1+1]) (f[o1][o2+1][t1+1]+=f[o1][o2][t1])%=mod; } cout<<f [m] <<endl; return 0; }
相关文章推荐
- bzoj 1566 NOI 2009 管道取珠 DP 解题报告
- [BZOJ 1566][NOI2009]管道取珠(DP)
- [平方的拆分 DP] BZOJ 1566 [NOI2009]管道取珠
- 【bzoj1566】【NOI2009】【管道取珠】【dp】
- bzoj 1566: [NOI2009]管道取珠【dp】
- 【BZOJ 1566】 1566: [NOI2009]管道取珠 (DP)
- bzoj 1566: [NOI2009]管道取珠 (DP)
- [BZOJ1566][NOI2009]管道取珠(DP)
- BZOJ1566 [NOI2009]管道取珠 dp
- BZOJ1566 [NOI2009]管道取珠 【dp】
- 【BZOJ】1566: [NOI2009]管道取珠
- bzoj1566 [NOI2009]管道取珠
- 1566: [NOI2009]管道取珠 - BZOJ
- BZOJ 1566: [NOI2009]管道取珠
- BZOJ1566 [NOI2009]管道取珠
- BZOJ1566: [NOI2009]管道取珠
- BZOJ1566:[NOI2009]管道取珠——题解
- bzoj1566: [NOI2009]管道取珠
- [bzoj1566][NOI2009]管道取珠
- BZOJ 1566 【NOI2009】 管道取珠