hdu没法提交,我以为我账号又崩了...
#include<iostream> #include<cstring> using namespace std; int T,n,m,k,kase; int color[30],ans[10][10]; bool DFS(int x,int y,int cur){ if(x>n) return true; for(int i=1;i<=k;i++){ if(!color[i] || ans[x-1][y]==i || ans[x][y-1]==i) continue; color[i]--; ans[x][y]=i; if(y<m && DFS(x,y+1,cur+1)) return true; else if(y==m && DFS(x+1,1,cur+1)) return true; color[i]++; } return false; } signed main(){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); cin>>T; while(T--){ cin>>n>>m>>k; for(int i=1;i<=k;i++) cin>>color[i]; cout<<"Case #"<<++kase<<":"<<endl; if(DFS(1,1,1)){ cout<<"YES"<<endl; for(int i=1;i<=n;i++){ cout<<ans[i][1]; for(int j=2;j<=m;j++) cout<<" "<<ans[i][j]; cout<<endl; } }else cout<<"NO"<<endl; } return 0; }
标签:hdu,5113,int,DFS,Black,White From: https://www.cnblogs.com/accbulb/p/18016320