周末总结

背包问题
f[i][v]=max{f[i-1][v],f[i-1][v-c[i]]+w[i]}
f[v]=max{f[v],f[v-c[i]]+w[i]}//表示前i件物品的取值至于前i-1件物品的状态值有关,可省略一维

目前主要是套公式。
伪码
for i=1… N
for v=0… V
f[v]=max{f[v], f[v-c[i]+w[i]};

完全背包 多重背包
f[i][j]只与f[i-1][j]和
f[i][j-w[i]]+v[i]有关。考虑
f[i][j]时,由于是从前往后
写,一维数组表示的f[j]
还没被写入,它表示的是
f[i-1][j],而f[j-w[i]]已经被写
入,它表示的是f[i][j-w[i]]
一维的f[v]=max{f[v],
f[v-w[i]]+v[i]}
表示的恰好是二维的
f[i][v]=max{f[i-1][v],f[i][v-w[i]]+v[i]}

星期天的比赛
A.Potion-making
You have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain exactly k % magic essence and (100−k) % water.

In one step, you can pour either one liter of magic essence or one liter of water into the cauldron. What is the minimum number of steps to brew a potion? You don’t care about the total volume of the potion, only about the ratio between magic essence and water in it.

#include<iostream>
using namespace std;

int main()
{
    int t;
    int k;
    int sum;
    cin>>t;
    while(t--)
    {
        cin>>k;
        sum=100;
        while(k%2==0) 
        { k=k/2;
          if(sum%2!=0) 
          break;
          sum=sum/2;
          
        }
        while(k%5==0) 
        { k=k/5;
          if(sum%5!=0) 
          break;
          sum=sum/5;
        }
        cout<<sum<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值