50061. Donation
難度:4/5
Second Try: 2.5/5 Used Time (Using array): 9:45 Used Time (Using bit): 5:301
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#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <stdint.h>
int n;
int dot[64];
int arr[64][64];
int max_dot = -1;
static inline int max(int a, int b){
if(a > b) return a;
return b;
}
static inline void ipt(){
scanf("%d", &n);
for(int i = 0; i < n; i++) scanf("%d", &dot[i]);
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) scanf("%d", &arr[i][j]);
}
void dfs(int now_idx, int now_dot, int now_can_dot[64]){
if(now_idx == n){
max_dot = max(max_dot, now_dot);
return;
}
if(now_can_dot[now_idx] == 0){
dfs(now_idx + 1, now_dot, now_can_dot);
}
else{
dfs(now_idx + 1, now_dot, now_can_dot);
int tmp[64];
for(int i = 0; i < n; i++) tmp[i] = now_can_dot[i];
for(int i = 0; i < n; i++){
if(arr[i][now_idx] == 1) tmp[i] = 0;
}
dfs(now_idx + 1 , now_dot + dot[now_idx], tmp);
}
}
int main(){
ipt();
int now_can_dot[64];
for(int i = 0; i < n; i++) now_can_dot[i] = 1;
dfs(0, 0, now_can_dot);
printf("%d\n", max_dot);
}