当前位置:网站首页>Luogu p1441 weight weighing
Luogu p1441 weight weighing
2022-07-27 11:14:00 【ThXe】
#include<bits/stdc++.h>
using namespace std;
int n, m, ans;
int a[25], st[25], f[2005];//a The array represents the weight of the weights , st[i] On behalf of the i Whether a weight has been discarded 1 To be abandoned 0 For not being abandoned , f Backpack for existence
int dp() {
memset(f, 0, sizeof f);
f[0] = 1;// Weight is 0 There must be a starting point
int res = 0, tot = 0;//res= this dp answer ,tot Total current weight
for (int i = 0; i < n; i++)
{
// st[i]=0 It means not to be abandoned , Then backpack it
if (!st[i]) {
for (int j = tot; j >= 0; j--)// At present, the maximum possible weight of the composition is tot
if (f[j] && !f[j + a[i]])f[j + a[i]] = 1, res++;// If j There is so j+a[i] There must be Remember not to double calculate
tot += a[i];// maintain tot
}
}
return res;
}
void dfs(int i, int now)// The first i Whether to abandon the weight Currently, the weight quantity has been discarded
{
if (now > m)return;// Abandon greater than m Cut directly
if (i > n)return;// exceed n A weight is also pruned
if (i == n && now == m) {
ans = max(dp(), ans); return; }// When the conditions are met, run again 01 Existential knapsack
dfs(i + 1, now);// The current weight is not discarded , that now unchanged
st[i] = 1;dfs(i + 1, now + 1);st[i] = 0;// The current weight is discarded that st[i]=1 Indicates abandonment of No i A weight ,now+1, Return to the original state after completion
}
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i++)cin >> a[i];
dfs(0, 0);
cout << ans << endl;
}
边栏推荐
- Description and feelings
- 泰山OFFICE技术讲座:缩放比例与打开文件
- Research on synaesthesia integration and its challenges
- 正则form表单判断
- An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft
- Miscellaneous records of Finance
- 荒野觅踪---寻找迭代次数
- 2022牛客多校训练(3)A-Ancestor 题目翻译
- 学习笔记-uni-app
- Error: image clipToBoundsAndScale, argument 'input'
猜你喜欢

Wechat push - template message parameter configuration

antd table中排序th阻止悬停变色+table悬停行变色+table表头变色

迭代次数和熵之间关系的一个验证试验

KEPServer配置

Chengying, kangaroo cloud one-stop fully automated operation and maintenance steward, is officially open source

熵与形态的非递进现象

Longest ascending subsequence model acwing 1012. Sister Cities

荒野觅踪---寻找迭代次数

What is the mystery of the gate of the meta universe?

2022牛客多校 (3)J.Journey
随机推荐
神经网络学习笔记
6 find the smallest letter larger than the target letter
Learning notes - wechat payment
Redis+caffeine two-level cache enables smooth access speed
4 search insertion location
Chunjun supports DDL conversion and automatic execution of heterogeneous data sources - dtmo 02 review (including course playback + courseware)
Longest ascending subsequence model acwing 482. Chorus formation
Yiwen counts NFT projects valued at more than US $100million
Neural network learning notes
SQL Server2000 database error
TensorFlow张量运算函数集
The article will not keep VIP charges all the time. It will be open for a period of time
推导重叠积分的详细展开式 STO overlap integrals
What is the mystery of the gate of the meta universe?
图片中非0值的数量对分类的影响
Today's code farmer girl learned notes about event operation and ref attribute, and did the practice of form two-way binding
推导STO双中心动能积分的详细展开式
Local and overall differences between emergence and morphology
parsel的使用
深析C语言的灵魂 -- 指针