UVA - 12260 Free Goodies
2013-12-23 21:54
211 查看
题意:觉得学长写的很好,借鉴了:点击打开链接
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int INF = 0x3f3f3f3f; const int MAXN = 1010; struct node{ int x,y; bool operator <(const node &a)const { if (x != a.x) return x > a.x; return y < a.y; } }arr[MAXN]; int n; int f[MAXN][MAXN/2]; int cost[MAXN][MAXN/2]; char name[10]; int main(){ int t; scanf("%d",&t); while (t--){ scanf("%d",&n); scanf("%s",name); int sum = 0; for (int i = 1; i <= n; i++){ scanf("%d%d",&arr[i].x,&arr[i].y); sum += arr[i].x; } sort(arr+1,arr+1+n); memset(f,0,sizeof(f)); memset(cost,0,sizeof(cost)); int cur = 0; for (int i = (name[0]=='P'?2:1); i <= n; i++){ ++cur; for (int j = 1; j <= (cur+1)/2; j++){ int &ans = f[i][j] = f[i-1][j]; cost[i][j] = cost[i-1][j]; if (j == 1 || f[i-1][j-1]){ int tmp = f[i-1][j-1] + arr[i].y; if (tmp > ans){ ans =tmp; cost[i][j] = cost[i-1][j-1] + arr[i].x; } else if (tmp == ans) cost[i][j] = min(cost[i][j],cost[i-1][j-1]+arr[i].x); } } } printf("%d %d\n",sum-cost [(cur+1)/2],f [(cur+1)/2]); } return 0; }
相关文章推荐
- uva 12260 - Free Goodies (dp,贪心 | 好题)
- Free Goodies - UVa 12260 dp
- uva 12260 - Free Goodies(dp+贪心)
- uva12260 - Free Goodies 贪心+dp
- UVA-12260-Free Goodies
- uva 12260 - Free Goodies (dp,贪心 | 好题)
- UVA 12260 Free Goodies (DP)
- UVA - 12260 Free Goodies(dp比较难想到)
- UVA 12260 - Free Goodies(dp+贪心)
- Free Goodies UVA - 12260
- uva 12260 Free Goodies DP+一点点贪心
- uva 12260(dp)
- uva12260(DP)
- UVALive 4945 Free Goodies
- UVALive 4945 Free Goodies
- UVA 12260 (思路dp)
- UVa 106 && POJ 1305 - Fermat vs. Pythagoras(毕达哥拉斯三元组)
- UVALive:6182 Ginkgo Numbers
- 数学专项counting:UVa 10237
- uva 572