結果

提出番号 1933
提出者 ok
言語 C++
提出日時 2018-08-04 14:37:57
問題名 (70)アルゴリズムのお勉強
結果 TLE
点数 0%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 WA 0% 2ms 8336KB
2 WA 0% 2ms 7504KB
3 WA 0% 2ms 8352KB
4 WA 0% 2ms 8256KB
5 WA 0% 2ms 8192KB
6 WA 0% 4ms 8352KB
7 WA 0% 1ms 8720KB
8 AC 100% 2ms 8080KB
9 WA 0% 2ms 7808KB
10 WA 0% 2ms 8704KB
11 WA 0% 316ms 8080KB
12 WA 0% 30ms 7920KB
13 WA 0% 264ms 8736KB
14 WA 0% 31ms 8736KB
15 WA 0% 31ms 8256KB
16 WA 0% 2ms 8720KB
17 WA 0% 2ms 8064KB
18 WA 0% 2ms 7808KB
19 TLE 0% 3715ms 8176KB
20 TLE 0% 3675ms 8304KB
21 WA 0% 2ms 7824KB
22 TLE 0% 20002ms 0KB
23 WA 0% 5ms 8080KB
24 TLE 0% 20002ms 0KB
25 TLE 0% 3684ms 8704KB
26 TLE 0% 20001ms 0KB
27 TLE 0% 20002ms 0KB
28 TLE 0% 3705ms 8736KB
29 TLE 0% 20002ms 0KB
30 TLE 0% 20002ms 0KB

ソースコード

#include<bits/stdc++.h>
using namespace std;

int N, a[20][20], t[20], temp[20][20];

int foo(int te[], int x){//cout<<endl<<x<<endl;
	if(x >= N)return 0;
	int ans = 10101010, te2[20] = {}, te3[]={}, co=0, te4;
	for(int i = 0; i < N; i++){//cout<<te[i]<<endl;
		te2[i]=te[i];
		if(te[i]==1)te3[co++] = i;
	}
	for(int i = 0; i < N; i++){
		if(te[i]==1)continue;
		int ma = 0;
		for(int j = 0; j < co; j++){//cout<<"   "<<j<<" "<<i<<" "<<a[j][i]<<endl;
			ma+=a[te3[j]][i];
		}//cout<<endl;
		
		te4 =t[i]-ma;
		//cout<<te4<<" "<<t[i]<<" "<<i<<" "<<ma<<endl;
		te2[i]=1;
		ans = min(foo(te2, x+1)+te4, ans);
		te2[i]=0;
	}
	return ans;
}
int main(){
	cin>>N;
	for(int i = 0; i < N; i++)cin>>t[i];
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			cin>>a[i][j];
		}
	}
	/*for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			int ma = 0;
			for(int k = 0; k < j; k++){
				if(ma < a[k][j])ma=a[k][j];
			}
			
		}
	}*/
	int te[20] = {};
	cout<<foo(te, 0)<<endl;
	return 0;
}