菜鸡不懂为什么 80 分。
查看原帖
菜鸡不懂为什么 80 分。
510555
ImposterAnYu楼主2021/11/20 11:58
#include<bits/stdc++.h>
using namespace std;
int n,m,i,j,a[30],b[30][20],p[30],t = INT_MAX,k[20],kk[20];
bool w(int g){
    for(int i = 1; i <= n; i++){
        int d = 0;
        for(int j = 1; j <= g; j++){
            d += b[k[j]][i];
        }
        if(d < a[i]){
        	return 0;
        }
    }
    return 1;
}
void anyu(int l,int s){
    if(l > m){
        if(w(s)){
	        if(s < t){
	        	t = s;
	        	for(int i = 1; i <= s; i++){
	        		kk[i] = k[i];
	        	}
	        }
        }
        return ;
    }
    k[s + 1] = l;
	anyu(l + 1,s + 1);
	anyu(l + 1,s);
	return ;
}
int main(){
	cin >> n;
	for(i = 1; i <= n; i++){
		cin >> a[i];
	}
	cin >> m;
	for(i = 1; i <= m; i++){
		for(j = 1; j <= n; j++){
			cin >> b[i][j];
		}
	}
	anyu(1,0);
	cout<< t << " " ;
	for(i = 1; i <= t; i++){
		cout<< kk[i] << " " ;
	}
	return 0;
}

#2 input:

25
826 953 853 512 620 769 722 833 719 754 730 521 908 622 877 737 534 882 560 812 684 787 984 983 783
15
167 78 129 9 41 56 71 132 29 45 61 152 13 76 172 152 27 21 0 38 24 93 25 155 18
84 69 79 59 179 166 107 28 79 63 11 101 95 73 172 70 141 97 72 170 74 132 48 195 136
88 97 174 121 28 28 157 29 56 148 1 46 160 188 114 179 49 55 22 20 79 98 144 153 100
98 23 58 152 58 197 72 199 1 171 18 57 61 64 78 100 61 192 135 92 80 168 129 144 192
178 80 119 78 95 14 15 102 26 135 127 145 130 95 117 193 95 98 19 163 135 81 74 182 85
121 35 187 43 113 58 56 152 56 183 162 76 90 43 138 38 142 107 156 197 105 81 95 29 9
182 124 77 118 106 55 143 6 18 194 92 145 159 61 132 59 12 80 144 179 39 42 122 51 102
14 107 32 188 114 67 127 165 15 100 102 183 5 34 125 28 69 180 69 71 2 114 131 107 45
64 107 118 27 151 160 74 129 77 35 188 35 105 160 148 189 122 177 144 139 33 145 5 59 74
162 74 58 98 48 123 149 6 35 148 93 2 103 144 189 28 108 91 26 49 150 64 81 166 119
87 144 20 64 49 93 51 132 105 185 91 115 74 169 46 154 55 17 159 42 188 163 189 73 161
36 7 65 4 4 162 132 166 89 82 10 13 182 92 118 157 123 106 168 127 158 169 84 21 159
112 73 38 102 93 185 119 195 97 10 14 156 146 54 190 26 111 44 109 18 83 91 78 193 164
175 7 54 63 78 84 60 156 20 84 140 183 130 142 14 41 17 97 14 60 155 27 184 9 156
103 173 20 51 174 96 90 35 196 77 122 23 137 43 195 41 70 89 4 26 64 186 170 51 13

#2 output:

10 2 3 5 6 7 8 9 11 13 15

my output

11 1 2 3 4 6 7 8 9 11 12 15 
2021/11/20 11:58
加载中...