Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

1000AC記念

Posted by tozangezan at 2011-12-20 00:02:39 on Problem 2220
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator