标签:namespace efi 01背包 for include log set pre i++
#include<bits/stdc++.h> #define MAXN 10005 using namespace std; int dp[MAXN][MAXN]; int w[MAXN],v[MAXN]; int t,n; int dfs(int i,int j) { if(i>n||i<0||j>t||j<0) return 0; if(dp[i][j]!=0) return dp[i][j]; if(j>w[i]) { dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]); } else dp[i][j]=dp[i-1][j]; return dp[i][j]; } int main() { while(cin>>t>>n) { memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) { cin>>w[i] >>v[i]; } dfs(n,t); cout<<dp[n][t]<<endl; } return 0; }
标签:namespace efi 01背包 for include log set pre i++
原文地址:http://www.cnblogs.com/KyleDeng/p/6763765.html