Address: Click to open the link
Test instructions: Just buy a 8-point drink, and then you have 1,5,10 three different coins.
Then ask to buy a C bottle of drinks, buy one at a time, your minimum coin count.
There are several ways we can: 1: Cast 8 one cent 2: cast a 5-point 3 1-point
3: Cast a 10 points to find 3 a point of 4: cast a 10 points of 3 a point, find a 5-point
There are other options but not too cost-effective.
#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <string > #include <iostream> #include <queue> #include <cmath> #include <map> #include <stack> #include <bitset>using namespace std; #define REPF (I, A, b) for (int i = A; I <= B; + + i) #define REP (i, n ) for (int i = 0; i < n; + + i) #define CLEAR (A, X) memset (A, x, sizeof a) typedef long long Ll;typedef pair& lt;int,int>pil;const int INF = 0x3f3f3f3f;const int Maxn=1100;char str[maxn];int dp[1100][155][55];int n1,n2,n3,c; int dfs (int num,int x1,int x2,int x3)//num,1,5,10{if (num==0) return 0; int &res=dp[x1][x2][x3]; if (res!=-1) return res; Res=inf; if (x3>=1) res=min (Res,dfs (num-1,x1+2,x2,x3-1) +1); if (x2>=2) res=min (Res,dfs (num-1,x1+2,x2-2,x3) +2); if (x1>=8) res=min (Res,dfs (num-1,x1-8,x2,x3) +8); if (x1>=3&&x3>=1) res=min (Res,dfs (num-1,x1-3,x2+1,x3-1) +4); if (x1>=3&&x2>=1) Res=min (Res,dfs (num-1,x1-3,x2-1,x3) +4); return res;} int main () {int t; scanf ("%d", &t); while (t--) {scanf ("%d%d%d%d", &c,&n1,&n2,&n3); CLEAR (dp,-1); printf ("%d\n", DFS (C,N1,N2,N3)); } return 0;}
UVA 10626 Buying Coke (memory)