Test instructions: A person campaigning, spending money canvassing, each community has the corresponding information, according to the formula to calculate the number of votes (rounding) the same time (according to the first community, the most cost, and so on)
Train of thought: even when the result is the same, according to the cost of the former community is more accurate, then obviously we have to push from the forward, according to the idea of the backpack, Dp[i][j] represents the largest number of votes from the community of N-1 to the community of J-k
The other place is to mark the cost of the first I
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace
Std
const int MAXN = 110; struct node{int n,ip,r;}
ARR[MAXN];
int DP[MAXN][MAXN],F[MAXN][MAXN];
int n,m;
int main () {int t = 1;
while (scanf ("%d%d", &m,&n) && n+m) {memset (dp,0,sizeof (DP));
memset (F,0,sizeof (f));
printf ("Case%d:", t++); for (int i = 0; i < n; i++) scanf ("%d%d%d", &arr[i]. N,&arr[i]. Ip,&arr[i].
R); for (int i = 0; I <=; i++) {Dp[n-1][i] = (arr[n-1]. ip+i/(i+10.1) *arr[n-1]. R)/100*arr[n-1].
n+0.5;
F[n-1][i] = i; } for (int i = n-2, i >= 0; i--) for (int j = 0; J <=; J + +) {int Max = 0,max
K for (int k = 0; k <= J; k++) {int temp = (int) (dp[i+1][j-k]+ (arr[i). ip+k/(k+10.1) *arr[i]. R)/100*arr[i].
n+0.5);
if (temp >= Max) { Max = temp;
Maxk = k;
} Dp[i][j] = Max;
F[I][J] = maxk;
}} printf ("%d\n", Dp[0][m]);
int temp = M,flag = 1;
for (int i = 0; i < n; i++) {if (flag) {printf ("%d:%d", I,f[i][temp]);
Flag = 0;
} else printf ("%d:%d", I,f[i][temp]);
Temp-= f[i][temp];
} printf ("\ n");
} return 0; }