Codeforces Round #659 (Div. 2) B1. Koa and the Beach(DP)

题目链接

思路:

DP记录每秒的海域状态,看你能否到达对面。

代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N=1e2+5,M=2e4+5;
const double eps=1e-8;
const int mod=1e9+7;
const int inf=0x7fffffff;
const double pi=3.1415926;
int a[N],p[2*N],f[N][M];
void init(int k)
{
	for(int i=0;i<=k;i++)
    {
        p[i]=i;
    }
	for(int i=1;i<k;i++)
    {
        p[k+i]=k-i;
    }
	for(int i=0;i<2*k;i++)
	{
	    f[0][i]=1;
	}
}
signed main()
{
    IOS;
	int t;
	cin>>t;
	while(t--)
	{
		memset(f,0,sizeof f);
		int n,k,l;
		cin>>n>>k>>l;
		for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
		init(k);
		for(int i=1;i<=n;i++)
        {
            for(int j=0;j<2*k*n;j++)
            {
                f[i][j]=max(f[i][j-1],f[i-1][j-1]);
                if(l<p[j%(2*k)]+a[i])
                {
                    f[i][j]=0;
                }
            }
        }
		bool ok=false;
		for(int i=0;i<2*k*n;i++)
        {
            if(f[n][i])
			{
			    ok=true;
			}
        }
		if(ok)
		{
		    cout<<"Yes"<<endl;
		}
		else
        {
            cout<<"No"<<endl;
        }
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/ACkingdom/article/details/107646559