D. Yet Another Number Game 夜

http://codeforces.com/contest/282/problem/D

理解上去并不难 就是 博弈论 用 dp 实现

但是用记忆化搜索时间复杂度太高 需要用递推 用奇异状态去更新非奇异状态 没被更新到的就是奇异状态

这样的话只有奇异状态才去更新  奇异状态相比非奇异状态要少很多 所以节约了大量时间

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<queue>
#include<stack>
#include <iomanip>
using namespace std;
#define LL long long
#define ULL unsigned long long
const double eps=1e-6;
const int INF=0x3f3f3f3f;
int main()
{
    //freopen("data.in","r",stdin);
    int n;
    while(cin>>n)
    {
        int a,b,A=0,B=0;
        while(n--)
        {
            cin>>a>>b;
            if(abs(A+a-B)<=500)
            {cout<<"A";A+=a;}
            else
            {cout<<"G";B+=b;}
        }
        cout<<endl;
    }

    return 0;
}

  

原文地址:https://www.cnblogs.com/liulangye/p/2959122.html