您的位置:首页
UVA - 812 Trade on Verweggistan
2017-05-04 19:49
579 查看
题意:首先给你个w,表示几组货物。然后给你n以及n个数表示价格,10-价格是利润
每次仅仅能取前i个,求最多的利润相应几个货物,不超过10个解
思路:首先是简单的计算最大的利润。然后就是储存全部的解。然后深搜出全部的可能
每次仅仅能取前i个,求最多的利润相应几个货物,不超过10个解
思路:首先是简单的计算最大的利润。然后就是储存全部的解。然后深搜出全部的可能
#include <iostream> #include <cstring> #include <algorithm> #include <cstdio> #include <queue> #include <vector> #include <set> using namespace std; const int MAXN = 100; int w, val[MAXN][MAXN]; set<int > ans; vector<int > p[MAXN]; void cal(int n, int sum) { if (n == w) { ans.insert(sum); return; } for (int i = 0; i < p .size(); i++) cal(n+1, sum+p [i]); } void solve() { ans.clear(); int valMax[MAXN], valSum, pro; valSum = 0; memset(valMax, 0, sizeof(valMax)); for (int i = 0; i < w; i++) { p[i].clear(); pro = 0; for (int j = 1; j <= val[i][0]; j++) { pro += 10 - val[i][j]; valMax[i] = max(valMax[i], pro); } valSum += valMax[i]; if (valMax[i] == 0) p[i].push_back(0); pro = 0; for (int j = 1; j <= val[i][0]; j++) { pro += 10 - val[i][j]; if (valMax[i] == pro) p[i].push_back(j); } } cal(0, 0); printf("Maximum profit is %d.\n", valSum); printf("Number of pruls to buy:"); int cnt = 0; for (set<int>::iterator i = ans.begin(); i != ans.end() && cnt != 10; i++, cnt++) printf(" %d", *i); printf("\n"); } int main() { int t = 0; while (scanf("%d", &w) != EOF && w) { int b; for (int i = 0; i < w; i++) { scanf("%d", &val[i][0]); for (int j = 1; j <= val[i][0]; j++) scanf("%d", &val[i][j]); } if (t) printf("\n"); printf("Workyards %d\n", ++t); solve(); } return 0; }
相关文章推荐
- UVa 812 - Trade on Verweggistan(贪心)
- UVa 812 - Trade on Verweggistan 解题报告(枚举)
- UVA812-Trade on Verweggistan(暴力)
- uva 812 - Trade on Verweggistan(暴力)
- UVa 812 - Trade on Verweggistan (贪心+dfs)
- UVA - 812 Trade on Verweggistan
- UVA - 812 Trade on Verweggistan dfs + 贪心
- 812 - Trade on Verweggistan (暴力枚举)
- POJ 1874 Trade on Verweggistan
- poj 1874 Trade on Verweggistan
- poj-1874 Trade on Verweggistan *
- UVA812-Trade on Verweggistan(暴力)
- p1874_Trade on Verweggistan
- UVa 122 - Trees on the level
- UVa 825 - Walking on the Safe Side
- UVa 122 - Trees on the level
- Hell on the Markets UVA - 1614 贪心+思维
- Uva - 122 - Trees on the level
- uva 10129 - Play on Words
- UVA-10161 Ant on a Chessboard