本文共 808 字,大约阅读时间需要 2 分钟。
简单博弈 + dp(记忆化搜索)
代码:
#include #include #include #include #include #include #include #include #include #include using namespace std;//#pragma comment(linker,"/STACK:1000000000,1000000000")#define LL long longconst int INF=0x3f3f3f3f;const int N=10005;const int M=55;int win[N];int choose[M];int n,m;int dp(int x){ if(win[x]!=-1) return win[x]; if(x==0) { win[x]=1; return win[x]; } for(int i=0;i =0&&dp(x-choose[i])==2) {win[x]=1;break;} } if(win[x]==-1) win[x]=2; return win[x];}int main(){ //freopen("data.txt","r",stdin); while(scanf("%d %d",&n,&m)!=EOF) { for(int i=0;i >choose[i]; memset(win,-1,sizeof(win)); cout<
转载于:https://www.cnblogs.com/liulangye/archive/2012/10/18/2729148.html