Topcoder SRM 544 1000pt
来源:互联网 发布:新疆为什么网络管制 编辑:程序博客网 时间:2024/05/01 13:58
记忆化搜索
#include<iostream>#include<vector>#include<algorithm>#include<cstdio>#include<queue>#include<stack>#include<string>#include<map>#include<set>#include<cmath>#include<cassert>#include<cstring>#include<iomanip>using namespace std;#ifdef _WIN32#define i64 __int64#define out64 "%I64d\n"#define in64 "%I64d"#else#define i64 long long#define out64 "%lld\n"#define in64 "%lld"#endif#define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++)#define FFF(i,a) for( int i = 0 ; i < (a) ; i ++)#define FFD(i,a,b) for( int i = (a) ; i >= (b) ; i --)#define S64(a) scanf(in64,&a)#define SS(a) scanf("%d",&a)#define LL(a) ((a)<<1)#define RR(a) (((a)<<1)+1)#define pb push_back#define CL(Q) while(!Q.empty())Q.pop()#define MM(name,what) memset(name,what,sizeof(name))#define read freopen("in.txt","r",stdin)#define write freopen("out.txt","w",stdout)const int inf = 0x3f3f3f3f;const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;const double oo = 10e9;const double eps = 10e-9;const double pi = acos(-1.0);const int maxn = 55;const int mod = 1000000007;// i64 gcd(i64 a,i64 b){return b?gcd(b,a%b):a;}struct zz{int x;int y;int z;}zx;struct AliceBobShuffle{int countWays(vector <int> a, vector <int> b, vector <int> c, vector <int> d){int sa = a.size();int sb = b.size();int sc = c.size();int sd = d.size();if(sa+sb != sc+sd) return 0;int dp[maxn][maxn][maxn];bool hash[maxn][maxn][maxn];MM(dp,0);MM(hash,false);queue<zz>q;CL(q);zx.x = 0;zx.y = 0;zx.z = 0;q.push(zx);dp[0][0][0]=1;hash[0][0][0] = true;zz now,to;int f;while(!q.empty()){now = q.front();q.pop();f = now.x + now.y - now.z;if(now.x<sa && now.z<sc && a[now.x] == c[now.z]){to.x=now.x+1;to.y=now.y;to.z=now.z+1;dp[to.x][to.y][to.z] += dp[now.x][now.y][now.z];dp[to.x][to.y][to.z] %= mod;if(!hash[to.x][to.y][to.z]){hash[to.x][to.y][to.z] = true;q.push(to);}}if( now.x<sa && f<sd && a[now.x] == d[f]){to.x=now.x+1;to.y=now.y;to.z=now.z;dp[to.x][to.y][to.z] += dp[now.x][now.y][now.z];dp[to.x][to.y][to.z] %= mod;if(!hash[to.x][to.y][to.z]){hash[to.x][to.y][to.z] = true;q.push(to);}}if(now.y<sb && now.z<sc && b[now.y] == c[now.z]){to.x=now.x;to.y=now.y+1;to.z=now.z+1;dp[to.x][to.y][to.z] += dp[now.x][now.y][now.z];dp[to.x][to.y][to.z] %= mod;if(!hash[to.x][to.y][to.z]){hash[to.x][to.y][to.z] = true;q.push(to);}}if(now.y<sb && f<sd && b[now.y] == d[f]){to.x=now.x;to.y=now.y+1;to.z=now.z;dp[to.x][to.y][to.z] += dp[now.x][now.y][now.z];dp[to.x][to.y][to.z] %= mod;if(!hash[to.x][to.y][to.z]){hash[to.x][to.y][to.z] = true;q.push(to);}}}return dp[sa][sb][sc];}};
- Topcoder SRM 544 1000pt
- Topcoder SRM 569 1000pt
- topcoder srm 531 div2 600pt
- TOPCODER/SRM 566 DIVII(250、500、1000题)(1000PT暂未附上代码)
- SRM 596 1000pt
- Topcoder SRM 709 DIV 2 250pt Robofactory solution
- Topcoder SRM 709 DIV 2 500pt Permatchd2 solution
- Topcoder SRM536 div2 1000pt
- TopCoder SRM 474 DIV1 1000
- Topcoder SRM 635 div2 1000
- Topcoder SRM 636 div2 1000
- tc SRM 554 1000pt
- topcoder srm530 div.2 1000pt
- TopCoder SRM205 Div1 1000pt LongPipes
- TopCoder SRM 634 Div2 Problem 1000 - SpecialStrings
- Topcoder SRM 640 Div2 1000(巧妙数学题)
- Topcoder SRM 517 DIV2 1000 CuttingGrass
- Topcoder SRM 566 DIV2 1000 FencingPenguinsEasy
- 套接字究竟是什么?
- 安装monit
- 生成图片验证码的程序
- Windows API实现最最简单的窗口程序
- Spring mvc (三) [继承SimpleFormController配合formbean区别get和post请求]
- Topcoder SRM 544 1000pt
- 从老鼠试验毒药的算法想到的
- 推荐个结合控件
- 设计模式(十一)——单例模式
- <<探讨linux/unix>>之命令find
- Hadoop Shell Command
- 深入探讨 Java 类加载器
- Jdbc连接MySQL更改端口无效的解决方法
- 后缀数组的初步认识