标签:hdu2159
10 10 1 10 1 1 10 10 1 9 1 1 9 10 2 10 1 1 2 2
0 -1 1
#include <stdio.h> #include <string.h> #define maxn 102 int dp[maxn][maxn]; int max(int a, int b) { return a > b ? a : b; } int main() { freopen("stdin.txt", "r", stdin); int N, M, K, S; int a, b, i, j, k; while (~scanf("%d%d%d%d", &N, &M, &K, &S)) { memset(dp, 0, sizeof(dp)); while (K--) { scanf("%d%d", &a, &b); for (i = 1; i <= S; ++i) for (j = b; j <= M; ++j) dp[i][j] = max(dp[i][j], dp[i-1][j-b] + a); } if (dp[S][M] < N) { printf("-1\n"); } else { for (i = 1; i <= M; ++i) { if (dp[S][i] >= N) { printf("%d\n", M - i); break; } } } } return 0; }
标签:hdu2159
原文地址:http://blog.csdn.net/chang_mu/article/details/41556767