int main() {
cin >> n >> m;
for (int i = 1; i <= n; i ) cin >> s[i];
for (int i = 1; i <= n; i ) cin >> c[i], p += s[i] * c[i];
f[0] = 1;
for (int i = 1; i <= n; i ++ )
for (int j = p; j >= c[i]; j -- )
for (int k = 1; k * c[i] <= j && k <= s[i]; k ++ )
f[j] = max(f[j], f[j - k * c[i]] * k);
for (int i = 0; i <= p; i ++ )
if (f[i] >= m) {
cout << i;
break;
}
/*
由于花费较少,所以用 f[i][j] 代表前 i 件物品,不超过 j 所能达到的最大策略数
f[i][j] = max(f[i - 1][j], f[i - 1][j - k * c[i]] * k;
*/
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 4e5 + 10, M = 510;
int s[M], c[M];
long long n, m;
long long f[N];
int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i ++) cin >> s[i];
for(int i = 1; i <= n; i ++) cin >> c[i];
f[0] = 1;
for(int i = 1; i <= n; i ++)
{
for(int k = 1; k <= s[i]; k ++)
{
for(int j = 2e5 + 10; j >= k * c[i]; j --)
{
f[j] = max(f[j], f[j - k * c[i]] * k);
}
}
}
long long ans = 1e18;
for(int i = 1; i <= N; i ++)
{
if(f[i] >= m)
{
ans = min(ans, (long long)i);
//cout << f[i] << endl;
}//cout << f[n & 1][i] << endl;
}
cout << ans << endl;
return 0;
}
#include [HTML_REMOVED]
#include [HTML_REMOVED]
#include [HTML_REMOVED]
using namespace std;
typedef long long i64;
const int N = 245000;
int n, p;
i64 m;
int s[N], c[N];
i64 f[N];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i ) cin >> s[i];
for (int i = 1; i <= n; i ) cin >> c[i], p += s[i] * c[i];
return 0;
佬,为什么要先枚举体积再枚举个数呢
为什么先枚举个数会出错呢
要先装得下,才会考虑装多少个
对啊,而且这个题当成多重背包做,就是这个代码我不知道为什么会有问题
错了,不是这样的