Portal
Pretreatment Plus Group backpack
n Rows m column, the cost of each column is the interval length of the first and last 1, known to remove no more than K 1, the minimum cost
#include <map>#include<cstdio>#include<cstring>#include<algorithm>#defineINF 0x3f3f3f3fusing namespacestd;Const intMAXN = 1e6 +Ten;intN, M, K;inta[510];intcst[510][510];intdp[510][510];intMain () {memset (CST, INF,sizeof(CST)); Memset (DP, INF,sizeof(DP)); scanf ("%d%d%d", &n, &m, &k); for(inti =1; I <= N; i++) {a[0] =0; inttmp; for(intj =1; J <= M; J + +) {scanf ("%1d", &tmp); if(TMP = =1) {a[++a[0]] =J; }} cst[i][0] = a[0] ==0?0: a[a[0]]-a[1] +1; for(intj =1; J < a[0]; J + +) { for(intKK =1; KK <= J +1; kk++) {Cst[i][j]= Min (Cst[i][j], a[a[0]-(J-kk +1)]-A[KK] +1); } } for(intj = a[0]; J <= K; J + +) Cst[i][j] =0; } dp[0][0] =0; for(inti =1; I <= N; i++) { for(intj =0; J <= K; J + +) { for(intKK =0; KK <= J; kk++) {Dp[i][j]= Min (Dp[i][j], dp[i-1][J-KK] +Cst[i][kk]); }}} printf ("%d\n", Dp[n][k]); return 0;}
946D. Timetable