10626-buying Coke

Source: Internet
Author: User

1 /*2 Test Instructions:3 That means there are 1,5,10 three kinds of coins, to buy Coke at the vending machine, Unit price 8,4 can only buy one bottle at a time, then the vending machine change, and then take the rest of the money to buy again,5 Given the amount of Coke to buy and the number of 1,5,10 three currencies, ask at least how many coins to give. 6 for example, 2 2 1 1, to buy 2 bottles of Coke, first give 10 pieces, the remaining 1,5,10 coins 4 1 0 pieces,7 give me another 5, 3, 1, so I'll give you a total of 5 coins .8 9 */Ten#include <cstdio> One#include <cstring> A#include <algorithm> - #defineINF 0x3f3f3f3f - using namespacestd; the intC,n1,n5,n10; - intdp[850][ -][ Max]; - intDfsintOintFintTintCNT) - { +     if(o*1+f*5+t*Ten<8)return 0; -     if(cnt = = c)return 0; +     if(dp[o][f][t]! = INF)returnDp[o][f][t]; A      at     if(T >=1)     -dp[o][f][t]= min (dp[o][f][t], DFS (o+2, f,t-1, cnt+1)+1);  -     if(F >=2)     -Dp[o][f][t] = min (dp[o][f][t], DFS (o+2, F-2, t,cnt+1)+2);  -     if(F >=1&& o >=3)     -Dp[o][f][t] = min (dp[o][f][t], DFS (o3, F-1, t,cnt+1)+4); in     if(o>=3&& t>=1 ) -Dp[o][f][t] = min (dp[o][f][t], DFS (o3, f+1, T1, cnt+1)+4); to     if(O >=8) +Dp[o][f][t] = min (dp[o][f][t], DFS (o8, f,t,cnt+1) +8 )    ;  -     returnDp[o][f][t]; the } * intMain () $ {Panax Notoginseng     intT; -scanf"%d",&t); the      while(t--) +     { Ascanf"%d%d%d%d",&c,&n1,&n5,&N10); thememset (Dp,inf,sizeof(DP)); +dp[0][0][0]=0; -DFS (N1,N5,N10,0); $printf"%d\n", Dp[n1][n5][n10]);  $     } -     return 0; - } the  - /*Wuyi #include <cstdio> the #include <cstring> - #include <algorithm> Wu #define INF 0x3f3f3f3f - using namespace std; About int c,n1,n5,n10; $ int dp[800][200][100]; - int dfs (int o,int f,int t,int cnt) - { - if (O*1+f*5+t*10 < 8) return 0; A if (cnt = = 0) return 0; + if (dp[o][f][t]! =-1) return dp[o][f][t]; the      - dp[o][f][t] = INF; $ if (t >= 1) the dp[o][f][t]= min (dp[o][f][t], DFS (o+2,f,t-1,cnt-1) +1);  the if (f >= 2) the dp[o][f][t] = min (dp[o][f][t], DFS (o+2,f-2,t,cnt-1) +2);  the if (f >= 1 && o >= 3) - dp[o][f][t] = min (dp[o][f][t], DFS (o-3,f-1,t,cnt-1) +4); in if (o>=3 && t>=1) the dp[o][f][t] = min (dp[o][f][t], DFS (o-3,f+1,t-1,cnt-1) +4); the if (o >=8) About dp[o][f][t] = min (dp[o][f][t], DFS (O-8,F,T,CNT-1) + 8);  the return dp[o][f][t]; the } the int main () + { - int t; the scanf ("%d", &t);Bayi While (t--) the     { the scanf ("%d%d%d%d", &c,&n1,&n5,&n10); - memset (Dp,-1,sizeof (DP)); - dp[0][0][0]=0; the DFS (N1,N5,N10,C); the printf ("%d\n", Dp[n1][n5][n10]);  the     } the return 0; - } the  the */

10626-buying Coke

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.