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 |
1000AC記念#include<stdio.h> #include<algorithm> using namespace std; char str[6]; int p,q; int dat[6][8]; int c[6]; int val[8]; int best[8]; int ret; void dfs(int a){ if(a==p){ int low=999999999; int high=0; for(int i=0;i<q;i++){ low=min(low,c[i]); high=max(high,c[i]); } int sa=high-low; if(sa<ret){ ret=sa; for(int i=0;i<p;i++){ best[i]=val[i]; } } return ; }else{ for(int i=0;i<q;i++){ val[a]=i; c[i]+=dat[i][a]; dfs(a+1); c[i]-=dat[i][a]; } return; } } int main(){ while(~scanf("%s",str)){ int a,b; ret=999999999; scanf("%d%d",&a,&b); p=a; q=b; for(int i=0;i<b;i++){ for(int j=0;j<a;j++)scanf("%d",&dat[i][j]); } scanf("%s",str); dfs(0); for(int i=0;i<b;i++){ int sum=0; for(int j=0;j<a;j++){ if(best[j]==i){ sum+=dat[i][j]; printf("%d ",1+j); } } printf("%d\n",sum); } printf("\n"); } } My 1000AC Code, No えだかり... Just a brute force... mofmof/\_/\ Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator