pku3093 Margaritas on the River Walk
2010-04-28 17:40
281 查看
题目链接:http://162.105.81.212/JudgeOnline/problem?id=3093
题意简述:从给定的一列数中选若干个数,使其和sum不能大于所给的限定m,并且m-sum<没被选的最小值,求种数。
解题思路:首先从大到小排序,然后对所有物品进行0、1决策。ps:从寒假wa到现在,就因为没加case数,晕。。。
代码:
题意简述:从给定的一列数中选若干个数,使其和sum不能大于所给的限定m,并且m-sum<没被选的最小值,求种数。
解题思路:首先从大到小排序,然后对所有物品进行0、1决策。ps:从寒假wa到现在,就因为没加case数,晕。。。
代码:
#include<stdio.h> #include<algorithm> using namespace std; int main() { int t; scanf("%d",&t); int Case=0; while(t--) { int v,d; int a[32],sum[32]={0},dp[32][1002]={0}; scanf("%d%d",&v,&d); for(int i=1;i<=v;i++) scanf("%d",&a[i]); sort(a+1,a+1+v); for(int i=1;i<=v;i++) sum[i]=sum[i-1]+a[i]; for(int i=1;i<=v;i++) for(int j=d;j>=1;j--) if(j>=sum[i]) dp[i][j]=1; else { dp[i][j]=dp[i-1][j]; if(j-a[i]>=0) { if(dp[i-1][j-a[i]]>0) dp[i][j]+=dp[i-1][j-a[i]]; else dp[i][j]++; } } printf("%d %d/n",++Case,dp[v][d]); } return 0; }
相关文章推荐
- POJ 3093 Margaritas on the River Walk(背包方案统计变型)
- poj 3093 Margaritas on the River Walk(01背包统计)
- POJ 3093 Margaritas on the River Walk 笔记
- poj 3093 Margaritas on the River Walk
- POJ 3093 Margaritas on the River Walk
- POJ 3093 Margaritas(Kind of wine) on the River Walk (背包方案统计)
- POJ 3093 Margaritas on the River Walk
- POJ 3093 Margaritas on the River Walk(背包)
- POJ 3093 Margaritas on the River Walk
- POJ 3093 Margaritas on the River Walk 背包DP
- POJ 3093 Margaritas on the River Walk 0-1背包好题
- POJ 3093 Margaritas on the River Walk
- pku 3039 Margaritas on the River Walk 背包dp 解题报告
- POJ 3093 Margaritas on the River Walk 0-1背包好题
- POJ 3093 Margaritas on the River Walk
- POJ - 3039 MARGARITAS ON THE RIVER WALK
- 【POJ3093】Margaritas on the River Walk【01背包变种】
- [POJ3093 Margaritas on the River Walk]
- poj - 3039 Margaritas on the River Walk
- poj3093 Margaritas on the River Walk(特殊的01背包)