1. 程式人生 > 實用技巧 >Codeforces Round #659 (Div. 2) B1. Koa and the Beach (Easy Version)

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

題意 小明從一岸游泳到另一岸,每片區域有水深,一旦水深超過L,小明就會淹死

同時每段時刻有海浪和退潮

搜尋一下 然後記憶化一下

老了,搜尋寫半天

#include<bits/stdc++.h>
using namespace std;
/*int main()
{
   // freopen("data2.in", "r", stdin);
   // freopen("data2.out", "w", stdout);
    int n,m;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        a[i]=a[i-1]+x;
    }

    cin>>m;
    while(m--)
    {

        int l,r;
        cin>>l>>r;
        if(l==r)
            cout<<a[l]-a[l-1]<<endl;
        else
            cout<<a[r]-a[l-1]<<endl;
    }
}
*/ int d[105]; int n,k,l; int vis[105][205]; int dfs(int x,int t) { if(vis[x][t]) return 0; vis[x][t]=1; int flag=0; if(x==n+1) return 1; t=t%(2*k); int ad; if(t<=k) ad=t; else ad=k-(t-k); if(x!=0&&(d[x]+ad)>l) return 0; flag
=max(flag,dfs(x+1,t+1)); t++; t=t%(2*k); if(t<=k) ad=t; else ad=k-(t-k); if(x>0) { if(d[x]+ad>l) return max(flag,0); } flag=max(dfs(x,t),flag); return flag; } int main() { int t; cin>>t; while(t--) { memset(vis,
0,sizeof(vis)); int flag=0; cin>>n>>k>>l; for(int i=1;i<=n;i++) { cin>>d[i]; if(d[i]>l) flag=1; } if(flag){cout<<"NO"<<endl;continue;} if(dfs(0,0))cout<<"YES"<<endl; else cout<<"NO"<<endl; } } /*int main() { // freopen("data.in", "r", stdin); //freopen("test.in", "w", stdout); int t; cin>>t; mt19937 u32Rnd(time(0)); cout<<t<<endl; while(t--) { int n; while((n=u32Rnd())<1); cout<<n<<endl; } }*/