标签:pac ring i++ 因特网 问题 std mes 一个 mat
#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <cstring> #include <cmath> using namespace std; #define ll long long #define ma (int)3e4+100 int n, m, v[40], p[40], dp[40][ma], w[40]; int main() { scanf("%d%d", &n, &m); for(int i = 0; i<m; i++) { scanf("%d%d", &v[i], &p[i]); w[i] = v[i]*p[i]; } for(int i = m-1; i >= 0; i--) { for(int j = 0; j <= n; j++) { if(j<v[i]) dp[i][j] = dp[i+1][j]; else dp[i][j] = max(dp[i+1][j], dp[i+1][j-v[i]]+w[i]); } } printf("%d\n", dp[0][n]); return 0; }
标签:pac ring i++ 因特网 问题 std mes 一个 mat
原文地址:https://www.cnblogs.com/RootVount/p/10351213.html