标签:bottom iostream long ios ant def others abc problem
http://acm.hdu.edu.cn/showproblem.php?pid=2476
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7666 Accepted Submission(s): 3738
//#include <bits/stdc++.h> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <algorithm> #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdio.h> #include <queue> #include <stack>; #include <map> #include <set> #include <string.h> #include <vector> #define ME(x , y) memset(x , y , sizeof(x)) #define SF(n) scanf("%d" , &n) #define rep(i , n) for(int i = 0 ; i < n ; i ++) #define INF 0x3f3f3f3f #define mod 998244353 #define PI acos(-1) using namespace std; typedef long long ll ; int dp[200005]; int w[209] , val[209]; int main() { int n ; while(~scanf("%d" , &n)) { for(int i = 0 ; i <= 200000 ; i++) dp[i] = -INF ; dp[100000] = 0 ; for(int i = 1 ; i <= n ; i++) { scanf("%d%d" , &w[i] , &val[i]); } for(int i = 1 ; i <= n ; i++) { if(w[i] < 0 && val[i] < 0) continue ; if(w[i] > 0) { for(int j = 200000 ; j >= w[i] ; j--) { if(dp[j-w[i]] > -INF) dp[j] = max(dp[j] , dp[j-w[i]]+val[i]); } } else { for(int j = w[i] ; j <= 200000 + w[i] ; j++) { if(dp[j-w[i]] > -INF) dp[j] = max(dp[j] , dp[j-w[i]]+val[i]); } } } int ans = -INF ; for(int i = 100000 ; i <= 200000 ; i++) { if(dp[i] >= 0) { ans = max(ans , dp[i]+i-100000); } } cout << ans << endl; } return 0 ; }
标签:bottom iostream long ios ant def others abc problem
原文地址:https://www.cnblogs.com/nonames/p/11748641.html