进制 #背包dp #贪心
注意到呈倍数的性质,考虑按照倍数转换进制,贪心的选择小的按顺序选择
// Author: xiaruize
const int INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1000000007;
const int N = 2e5 + 10;
int n, m;
int a[N], b[N];
pii s[N];
int cnt[N];
vector<int> vec;
int tot;
bool dec(int x)
{
if (x > tot)
return false;
if (cnt[x])
{
cnt[x]--;
return true;
}
if (dec(x + 1))
{
cnt[x] += s[x + 1].first / s[x].first;
cnt[x]--;
return true;
}
return false;
}
void solve()
{
cin >> n >> m;
rep(i, 1, n) cin >> a[i];
rep(i, 1, m) cin >> b[i];
sort(b + 1, b + m + 1);
rep(i, 1, m)
{
if (b[i] != s[tot].first)
s[++tot].first = b[i];
s[tot].second++;
}
per(i, tot, 1)
{
rep(j, 1, n)
{
cnt[i] += a[j] / s[i].first;
a[j] %= s[i].first;
}
}
int res = 0;
rep(i, 1, tot)
{
rep(j, 1, s[i].second)
{
if (!dec(i))
{
cout << res << endl;
return;
}
res++;
}
}
cout << res << endl;
}
#ifndef ONLINE_JUDGE
bool end_of_memory_use;
#endif
signed main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int testcase = 1;
// cin >> testcase;
while (testcase--)
solve();
#ifndef ONLINE_JUDGE
cerr << "Memory use:" << (&end_of_memory_use - &start_of_memory_use) / 1024.0 / 1024.0 << "MiB" << endl;
cerr << "Time use:" << (double)clock() / CLOCKS_PER_SEC * 1000.0 << "ms" << endl;
#endif
return 0;
}
标签:cnt,return,int,POI2007ODW,rep,tot,Weights,first
From: https://www.cnblogs.com/xiaruize/p/18136785