#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
vector<int> numcoin(6);
vector<int> coin={5,10,20,50,100,200};
vector<int> minway(1001,1000);
void mnway(){
minway[0]=0;
for(int i=5;i<=1001;i+=5){
int j=0;
while(j<6&&coin[j]<=i){
minway[i]=min(minway[i],1+minway[i-coin[j]]);
j++;
}
}
}
int cc(vector<vector<vector<int> > > &dp,int i,int cnt,int sum){
if(sum==0)return 0;
if(cnt>numcoin[i]){i++;cnt=1;}
if(i==6||coin[i]>sum||sum<0)return 1000;
if(dp[i][cnt][sum]!=-1)return dp[i][cnt][sum];
if(numcoin[i]>=cnt)return dp[i][cnt][sum]=min(cc(dp,i+1,1,sum),1+cc(dp,i,cnt+1,sum-coin[i]));
else return dp[i][cnt][sum]=cc(dp,i+1,1,sum);
}
int main(){
while(true){
vector<vector<vector<int> > > dp(6,vector<vector<int> >(101,vector<int>(1001,-1)));
int i=0,flag=0,ans=1<<30;
while(i<6){
cin>>numcoin[i];
if(numcoin[i]!=0)flag=1;
i++;
}
if(flag==0)return 0;
double n;
cin>>n;
mnway();
int m=round(100*n);
for(int i=m;i<=1000;i+=5){
ans=min(ans,cc(dp,0,1,i)+minway[i-m]);
}
cout<<setw(3)<<ans<<endl;
}
return 0;
}
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
vector<int> numcoin(6);
vector<int> coin={5,10,20,50,100,200};
vector<int> minway(1001,1000);
void mnway(){
minway[0]=0;
for(int i=5;i<=1001;i+=5){
int j=0;
while(j<6&&coin[j]<=i){
minway[i]=min(minway[i],1+minway[i-coin[j]]);
j++;
}
}
}
int cc(vector<vector<vector<int> > > &dp,int i,int cnt,int sum){
if(sum==0)return 0;
if(cnt>numcoin[i]){i++;cnt=1;}
if(i==6||coin[i]>sum||sum<0)return 1000;
if(dp[i][cnt][sum]!=-1)return dp[i][cnt][sum];
if(numcoin[i]>=cnt)return dp[i][cnt][sum]=min(cc(dp,i+1,1,sum),1+cc(dp,i,cnt+1,sum-coin[i]));
else return dp[i][cnt][sum]=cc(dp,i+1,1,sum);
}
int main(){
while(true){
vector<vector<vector<int> > > dp(6,vector<vector<int> >(101,vector<int>(1001,-1)));
int i=0,flag=0,ans=1<<30;
while(i<6){
cin>>numcoin[i];
if(numcoin[i]!=0)flag=1;
i++;
}
if(flag==0)return 0;
double n;
cin>>n;
mnway();
int m=round(100*n);
for(int i=m;i<=1000;i+=5){
ans=min(ans,cc(dp,0,1,i)+minway[i-m]);
}
cout<<setw(3)<<ans<<endl;
}
return 0;
}
Comments
Post a Comment