-
Notifications
You must be signed in to change notification settings - Fork 47
/
a.cpp
88 lines (72 loc) · 1.36 KB
/
a.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<bits/stdc++.h>
using namespace std;
const int MAX = 100000;
int n;
int x[MAX], y[MAX];
int p[MAX];
bool mark[MAX];
int min_tichvohuong;
int tichvohuong;
void input(){
cin >> n;
for(int i=0; i<n; i++){
cin >> x[i];
}
for(int i=0; i<n; i++){
cin >> y[i];
}
for(int i=0; i<n; i++){
mark[i] = false;
}
min_tichvohuong = INT_MAX;
tichvohuong = 0;
}
int tich_vo_huong(int a[MAX], int b[MAX], int n){
int tichvohuong = 0;
for(int i=0; i<n; i++){
tichvohuong += a[i]*b[i];
}
return tichvohuong;
}
bool check(int a, int i){
if(mark[i]){
return false;
}
return true;
}
void solution(){
if(tichvohuong < min_tichvohuong){
min_tichvohuong = tichvohuong;
}
}
int TRY(int a){
for(int i=0; i<n; i++){
if(check(a, i)){
mark[i] = true;
p[a] = y[i];
tichvohuong += x[a] * p[a];
if(a == n-1){
solution();
} else {
TRY(a + 1);
}
mark[i] = false;
tichvohuong -= x[a] * p[a];
}
}
}
void solve(){
input();
TRY(0);
}
int main(){
int T;
cin >> T;
int cnt = 1;
while(T>0){
solve();
cout << "Case #" << cnt << ": " << min_tichvohuong << endl;
cnt++;
T--;
}
}