Title: Vijos P1836hys and Tanabata festival big battle
Test instructions
n objects, per value VI, specific gravity PI, total capacity 100
Analysis:
Similar to the weight of the Backpack pi is a real number, not as subscript, so change the DP object
Will find the maximum value in capacity 100 → to find the minimum capacity of the corresponding value,
Then the value of the first ≤100 of the volume, which is the highest value of the value that meets the criteria
Status: Dp[v]: Minimum volume with a value of V
Transfer equation:
Dp[v] = min (Dp[v], Dp[v-v[i]] + p[i]);
Core:
for (i = 1; i<=n; i++)
{
for (j = sum_v; j>=v[i]; j--)
{
Dp[j] = min (Dp[j], Dp[j-v[i]] + p[i]);
}
}
Code:
#include <stdio.h> #include <iostream> #include <math.h> #include < algorithm> #include <string.h> #include <string> #include <queue> #include <stack> #include <map> #include <vector> #include <time.h> using
namespace std;
double p[1000+10];
int v[1000+10];
double dp[5*1000+10];
Int main () {//freopen ("a.txt", "R", stdin);
int n, i, j;
while (~SCANF ("%d", &n)) {int sum = 0;
for (i = 1; i<=n; i++) {scanf ("%lf%d", &p[i], &v[i]);
sum += v[i];
} memset (Dp, 0x4f, sizeof (DP));
dp[0] = 0; for (i = 1; i<=n; i++) {for (j = sum; j>=v[i]; j--) {dp[j]
= min (Dp[j], dp[j-v[i]] + p[i]);
}} while (dp[sum]>100) sum--; printf ("%d\n", sum);
} return 0; }