设为首页 加入收藏

TOP

UVA 10626 Buying Coke (记忆化)
2015-07-20 17:13:19 来源: 作者: 【 】 浏览:2
Tags:UVA 10626 Buying Coke 记忆

地址:点击打开链接

题意:就是买一个售价8分的饮料,然后你有的硬币有1,5,10分三种。

然后问买c瓶饮料,一次一次买,你最小的投币次数。

我们可以有几种方法:1:投8个一分 2:投一个5分的3个1分的

3:投一个10分的找3个一分的 4:投一个10分的3个一分的,找一个5分的

还有其他方案但是不是太划算。

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


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 1269 Intersecting Lines 下一篇LeetCode Combination Sum

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·有没有哪些高效的c++ (2025-12-27 08:20:57)
·Socket 编程时 Accep (2025-12-27 08:20:54)
·计算机网络知识点总 (2025-12-27 08:20:52)
·一篇说人话的文章, (2025-12-27 07:50:09)
·Python Web框架哪家 (2025-12-27 07:50:06)