标签:set cout pre ring -- lin sizeof efi namespace
hdu 1079 记忆化搜索
#include<bits/stdc++.h> #define rep(ii,a,b) for(int ii=a;ii<=b;++ii) #define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std;//head int casn,n,m,k,kasn; int vis[2100][15][40]; int day[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31}, {0,31,29,31,30,31,30,31,31,30,31,30,31}}; int dfs(int y,int m,int d){ if(~vis[y][m][d]) return vis[y][m][d]; int flag=0,r=(y%4==0&&y%100!=0)||(y%400==0); if(m<12&&day[r][m+1]>=d) flag|=!dfs(y,m+1,d); if(!flag){ if(d==day[r][m]){ if(m==12)flag|=!dfs(y+1,1,1); else flag|=!dfs(y,m+1,1); }else flag|=!dfs(y,m,d+1); } return vis[y][m][d]=flag; } int main() {IO; cin>>casn; memset(vis,-1,sizeof vis); rep(i,2001,2010)rep(j,1,12)rep(k,1,31){ if(i>2001) vis[i][j][k]=1; else if(j>11) vis[i][j][k]=1; else if(j==11&&k>4) vis[i][j][k]=1; } vis[2001][11][4]=0; while(casn--){ int y,m,d;cin>>y>>m>>d; if(dfs(y,m,d))cout<<"YES\n"; else cout<<"NO\n"; } }
gym100500A dfs+回溯
#include<bits/stdc++.h> #define ll long long #define rep(ii,a,b) for(int ii=a;ii<=b;++ii) #define per(ii,a,b) for(int ii=b;ii>=a;--ii) #define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std;//head const int maxn=30+10,maxm=2e6+10; int casn,n,m,k; int s1[maxn][maxn][2]; int cnt[2]; bool dfs(int now,int p){ if(cnt[p]==0) return false; bool flag=false; rep(i,0,25){ if(s1[now][i][p]){ s1[now][i][p]--; cnt[p]--; flag|=!dfs(i,1-p); s1[now][i][p]++; cnt[p]++; } } return flag; } int main() {IO; cin>>casn; int kase=0; while(casn--){ cin>>n; string s; memset(s1,0,sizeof s1); getline(cin,s); rep(i,1,n){ getline(cin,s); int a=s[0]-‘a‘; int b=s.back()-‘a‘; s1[a][b][0]++; } cin>>m; getline(cin,s); rep(i,1,m){ getline(cin,s); int a=s[0]-‘a‘; int b=s.back()-‘a‘; s1[a][b][1]++; } cnt[0]=n; cnt[1]=m; int flag=0; rep(i,0,25){ rep(j,0,25){ if(s1[i][j][0]){ s1[i][j][0]--; cnt[0]--; flag|=!dfs(j,1); s1[i][j][0]++; cnt[0]++; } } } cout<<"Game "<<++kase<<": player"<<2-flag<<‘\n‘; } }
标签:set cout pre ring -- lin sizeof efi namespace
原文地址:https://www.cnblogs.com/nervendnig/p/11637942.html