Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
暴力破解DFS#include <iostream> using namespace std; int y[9],x[9],seq[9],cnt,req[9],reqcnt,i,j; void DFS(int dq){ int i; if(dq==8) for(i=0;i<4;i++){ seq[dq] = i; cnt = 0; for(j=0;j<9;j++)cnt+=seq[j]; if(cnt<reqcnt) if(((seq[0]+seq[1]+seq[3])%4==y[0])&& ((seq[0]+seq[1]+seq[2]+seq[4])%4==y[1])&& ((seq[1]+seq[2]+seq[5])%4==y[2])&& ((seq[0]+seq[3]+seq[4]+seq[6])%4==y[3])&& ((seq[0]+seq[2]+seq[4]+seq[6]+seq[8])%4==y[4])&& ((seq[2]+seq[4]+seq[5]+seq[8])%4==y[5])&& ((seq[3]+seq[6]+seq[7])%4==y[6])&& ((seq[4]+seq[6]+seq[7]+seq[8])%4==y[7])&& ((seq[5]+seq[7]+seq[8])%4==y[8])) for(j=0;j<9;j++){ req[j] = seq[j]; reqcnt = cnt; } } else for(i=0;i<4;i++){ seq[dq] = i; DFS(dq+1); } } int main() { for(i=0;i<9;i++){ cin>>y[i]; y[i] = (4-y[i])%4; } reqcnt = 999; DFS(0); for(i=0;i<9;i++) for(j=0;j<req[i];j++)cout<<i+1<<' '; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator