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 200+(代码)#include<iostream> using namespace std; int N,dis[21][21],known[21]; int cnt; int dfs(int k,int d) { int t=d; //计算当第k台电脑放进第一组是的数据总量 for(int i=1;i<=N;i++) { if(known[i] ==1) t-=dis[k][i]; else t+=dis[k][i]; } // if(t>cnt) cnt=t; for(int i=k+1;i<=N;i++) { if(known[i]==0) { known[i]=1; //将第i台电脑放到第一组 dfs(i,t); known[i]=0; //不放 } } return 1; } int main() { cin>>N; for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) cin>>dis[i][j]; memset(known,0,sizeof(known)); cnt=0; dfs(0,0); cout<<cnt; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator