sicily1146.采药
来源:互联网 发布:windows phone停止维护 编辑:程序博客网 时间:2024/06/05 16:33
#include <iostream>#include <cstring>using namespace std;int max(int x, int y){ if (x > y) { return x; } else { return y; }}int main(){ int a[102], b[102]; int t, m; cin >> t >> m; for (int i = 1; i <= m; ++ i) { cin >> a[i] >> b[i]; } int fw[1002][102]; memset(fw, 0, sizeof(fw)); for (int i = 1; i <= t; ++ i) { for (int j = 1; j <= m; ++ j) { if (i >= a[j]) { fw[i][j] = max(fw[i][j - 1], fw[i - a[j]][j - 1] + b[j]); } else { fw[i][j] = fw[i][j - 1]; } } } cout << fw[t][m] << endl; //system("pause");}