贪心算法,简单的背包问题

xiaoxiao2021-02-28  61

有错纠错谢了。

#include <iostream>using namespace std;//硬币的面值const int v[6]={1,5,10,50,100,500};//输入int c[6];int a;int main(){    int ans=0;    cin >> a;    for(int j=0;j<6;j++){        cin >> c[j];}    for(int i =5;i>=0;i--){        int t = min(a/v[i],c[i]);//硬币使用的枚数        a-= t*v[i];        ans+=t;    }        cout << ans;}

转载请注明原文地址: https://www.6miu.com/read-2623485.html

最新回复(0)