UVA - 10626 Buying Coke
2013-09-27 20:04
411 查看
题意:给你四个数,分别代表要买的可乐的数量,价格为1,5,10的硬币数量,每瓶可乐价格是8,问买这些可乐最小要的硬币数量,每买一瓶返还的硬币数最少的可能。dp[c][x][y][z]的表示是最容易的,但显然空间占用太大,也容易想到
我们可以把第一个参数去掉,至于返还的可能也就5种,2*5,8*1,10*1,5*1+3*1,10*1+1*3,显然为了能够最少我们是从10这种硬币开始的
我们可以把第一个参数去掉,至于返还的可能也就5种,2*5,8*1,10*1,5*1+3*1,10*1+1*3,显然为了能够最少我们是从10这种硬币开始的
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n,n1,n2,n3,dp[710][160][160]; int DP(int c,int x,int y,int z){ if (dp[x][y][z]) return dp[x][y][z]; if (c == 0) return 0; if (z == 0 && y == 0) return dp[x][y][z] = c * 8; int Min = 1 << 20; if (z >= 1){ Min = DP(c-1,x+2,y,z-1)+1; if (x >= 3) Min = min(Min,DP(c-1,x-3,y+1,z-1)+4); return dp[x][y][z] = Min; } else { if (x >= 3) Min = min(Min,DP(c-1,x-3,y-1,z)+4); if (y >= 2) Min = min(Min,DP(c-1,x+2,y-2,z)+2); return dp[x][y][z] = Min; } } int main(){ int t; scanf("%d",&t); while (t--){ scanf("%d%d%d%d",&n,&n1,&n2,&n3); memset(dp,0,sizeof(dp)); int ans = DP(n,n1,n2,n3); printf("%d\n",ans); } return 0; }
相关文章推荐
- uva 10626 - Buying Coke(记忆化搜索)
- uva 10626 Buying Coke (DP + 记忆化搜索)
- uva 10626 - Buying Coke(记忆化搜索)
- uva 10626 - Buying Coke
- dp(UVa - 10626 Buying Coke)
- UVA - 10626 Buying Coke
- UVA - 10626 Buying Coke(记忆化搜索)
- UVA 10626 Buying Coke
- uva10626 - Buying Coke 记忆化搜索
- UVa 10626 Buying Coke(DP)
- uva 10626 - Buying Coke
- UVA - 10626 Buying Coke
- uva 10626 Buying Coke
- Buying Coke - UVa 10626 dp
- uva 10626 - Buying Coke(记忆化搜索)
- UVA 10626 Buying Coke (记忆化)
- uva 10626 Buying Coke
- uva 10626 Buying Coke (DP记忆化搜索)
- UVA 10626 Buying Coke
- UVA - 10626 Buying Coke 多状态