UVA 10626 Buying Coke (memory)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.