1050 [USACO 2009 Oct G]Bessie's Weight Problem 完全背包装箱问题
链接:https://ac.nowcoder.com/acm/problem/24851
来源:牛客网
题目描述
Bessie, like so many of her sisters, has put on a few too many
pounds enjoying the delectable grass from Farmer John's pastures.
FJ has put her on a strict diet of no more than H (5 <= H <= 45,000)
kilograms of hay per day.
Bessie can eat only complete bales of hay; once she starts she can't stop. She has a complete list of the N (1 <= N <= 500) haybales available to her for this evening's dinner and, of course, wants to maximize the total hay she consumes. She can eat each supplied bale only once, naturally (though duplicate weight valuess might appear in the input list; each of them can be eaten one time).
Given the list of haybale weights Wi (1 <= Wi <= H), determine the maximum amount of hay Bessie can consume without exceeding her limit of H kilograms (remember: once she starts on a haybale, she eats it all).
POINTS: 250
pounds enjoying the delectable grass from Farmer John's pastures.
FJ has put her on a strict diet of no more than H (5 <= H <= 45,000)
kilograms of hay per day.
Bessie can eat only complete bales of hay; once she starts she can't stop. She has a complete list of the N (1 <= N <= 500) haybales available to her for this evening's dinner and, of course, wants to maximize the total hay she consumes. She can eat each supplied bale only once, naturally (though duplicate weight valuess might appear in the input list; each of them can be eaten one time).
Given the list of haybale weights Wi (1 <= Wi <= H), determine the maximum amount of hay Bessie can consume without exceeding her limit of H kilograms (remember: once she starts on a haybale, she eats it all).
POINTS: 250
输入描述:
* Line 1: Two space-separated integers: H and N
* Lines 2..N+1: Line i+1 describes the weight of haybale i with a single integer: Wi
输出描述:
* Line 1: A single integer that is the number of kilograms of hay that Bessie can consume without going over her limit.
分析:
重复使用,就是完全背包的装箱问题嘛
//-------------------------代码----------------------------
//#define int ll
const int N = 1000;
int n,m;
int a[N];
int f[45100];
void solve()
{
cin>>m>>n;
// V<V<int>>mp(n+1,V<int>(m+1));
fo(i,1,n) cin>>a[i];
f[0] = 1;
fo(i,1,n) {
fo(j,a[i],m) {
f[j] = f[j] | f[j-a[i]];
}
}
int t;
of(i,m,0) {
if(f[i]) {
t = i;
break;
}
}
cout<<t<<endl;
}
signed main(){
clapping();TLE;
// int t;cin>>t;while(t -- )
solve();
// {solve(); }
return 0;
}
/*样例区
*/
//------------------------------------------------------------