Ultraviolet A 10626 Buying Coke (memory-based)

Source: Internet
Author: User
Tags bitset cmath

Ultraviolet A 10626 Buying Coke (memory-based)

Address: Click to open the link

Buy an 8-point drink, and you have three coins: 1, 5, and 10.

Then I asked you to buy a c-bottle drink, and buy one at a time. You have the minimum number of coins.

There are several ways to do this: 1: cast 8 points and 2: cast a 5-point 3 points and 1 point

3: If you place a score of 10, find the score of 3. If you place a score of 10, find the score of 5.

There are other solutions, but they are not too cost-effective.

#include
 
  #include
  
   #include#include
   
    #include
    
     #include
     
      #include
      
       #include
       
        #include
        #include
         
          #include
          
           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
           
            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;}
           
          
         
       
      
     
    
   
  
 


Related Article

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.