ACM: 动态规划题 poj 3093 0-1背包
来源:互联网 发布:win7如何安装linux系统 编辑:程序博客网 时间:2024/06/07 06:09
One of the more popular activities in SanAntonio is to enjoy margaritas in the park along the river know asthe River Walk. Margaritas may be purchased at manyestablishments along the River Walk from fancy hotels to Joe’sTaco and Margarita stand. (The problem is not to find out howJoe got a liquor license. That involves Texas politics and thus ismuch too difficult for an ACM contest problem.) The prices of themargaritas vary depending on the amount and quality of theingredients and the ambience of the establishment. You haveallocated a certain amount of money to sampling differentmargaritas.
Given the price of a single margarita (including applicabletaxes and gratuities) at each of the various establishments and theamount allocated to sampling the margaritas, find out how manydifferent maximal combinations, choosing at most one margarita fromeach establishment, you can purchase. A valid combination must havea total price no more than the allocated amount and the unusedamount (allocated amount – total price) must be less thanthe price of any establishment that was not selected. (Otherwiseyou could add that establishment to the combination.)
For example, suppose you have $25 to spend and the prices (wholedollar amounts) are:
VendorABCDHJPrice8987165
Then possible combinations (with their prices) are:
ABC(25), ABD(24), ABJ(22), ACD(23), ACJ(21), ADJ( 20), AH(24),BCD(24), BCJ(22), BDJ(21), BH(25), CDJ(20), CH(24), DH(23) andHJ(21).
Thus the total number of combinations is 15.
Input
The input begins with a line containing aninteger value specifying the number of datasets that follow,N (1 ≤ N ≤ 1000). Each dataset startswith a line containing two integer values V andD representing the number of vendors (1 ≤V ≤ 30) and the dollar amount to spend (1 ≤D ≤ 1000) respectively. The two values will beseparated by one or more spaces. The remainder of each datasetconsists of one or more lines, each containing one or more integervalues representing the cost of a margarita for each vendor. Therewill be a total of V cost values specified. The costof a margarita is always at least one (1). Input values will bechosen so the result will fit in a 32 bit unsignedinteger.
Output
For each problem instance, the output will be a single linecontaining the dataset number, followed by a single space and thenthe number of combinations for that problem instance.
Sample Input
2
6 25
8 9 8 7 16 5
30 250
1 2 3 4 5 6 7 8 9 10 11
12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
Sample Output
1 15
2 16509438
题意: 从n个物品选出一部分, 使它们的值累加起来Sum,如果Sum+a[i]任何一个不在Sum之内的值,
解题思路:
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAX 1005
#define MAXSIZE 32
int n, S;
int sum[MAXSIZE], a[MAXSIZE];
int dp[MAXSIZE*MAX];
inline int max(int a, int b)
{
}
int DP()
{
}
int main()
{
//
}
- ACM: 动态规划题 poj 3093 0-1背包
- ACM: 0-1背包变形 动态规划题 toj …
- ACM: 动态规划题 poj 3211 背包变…
- ACM: 简单动态规划题 poj 2955
- ACM: 动态规划题 poj 2241
- ACM: 动态规划题 poj 1054
- ACM: 动态规划题 poj 2948
- ACM: 动态规划题 poj 1925
- ACM: 动态规划题 poj 3034
- ACM: 动态规划题 poj 2411
- ACM: 动态规划题 poj 1947
- ACM: 动态规划题 poj 2486
- ACM: 动态规划题 poj 3140
- ACM: 动态规划题 poj 3659
- ACM: 动态规划题 poj 2923
- ACM: DP训练好题 动态规划题 poj 1…
- ACM: dp动态规划题(难) poj 3267 …
- ACM: dp题(动态规划) poj 2151 (d…
- 动态规划: 经典0-1背包问题 (转)
- ACM: 动态规划题 poj&nb…
- ACM: 动态规划题 poj 3211 背包变…
- (OK)(OK) Fedora23——NS3(MANETs)——Docker(busybox)——genymotion(android)——All is OK
- ACM: 动态规划题 poj&nb…
- ACM: 动态规划题 poj 3093 0-1背包
- ACM: 动态规划题 poj&nb…
- ACM: 动态规划题 poj 2923
- 兴趣学习: opencv -- 视频读写, 鼠…
- 兴趣学习: opencv 实现画图程序
- ACM: 图论题 poj 3…
- ACM: 动态规划题 poj&nb…
- ACM: 博弈题 poj 1143 状态压缩
- ACM: 图论题 poj 2186 强连通分量