Create 1441_Hawo11.cpp

https://blog.csdn.net/Hawo11/article/details/78345514
This commit is contained in:
Kirigaya Kazuto 2019-04-09 13:22:42 +08:00 committed by GitHub
parent a79cd82c9b
commit 6fc46aec14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

45
LuoGu/1441_Hawo11.cpp Normal file
View File

@ -0,0 +1,45 @@
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
const int N=20+2;
const int M=2000+5;
int n,m,w[N],dp[M],flag[N],top,ans=0,tot;
void work01()
{
memset(dp,0,sizeof(dp));
dp[1]=1;tot=0;top=1;
for (int i=1;i<=n;i++)
{
if (flag[i]==1) continue;
for (int j=top;j>=0;j--)
if (dp[j]&&!dp[j+w[i]]) dp[j+w[i]]=1,tot++;
top+=w[i];
}//滚动
ans=max(ans,tot);
}
void dfs(int u,int now)
{
if (now>m) return ;
if (u==n+1) {if (now==m) work01();return ;}
dfs(u+1,now);
flag[u]=1;
dfs(u+1,now+1);
flag[u]=0;
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++)
scanf("%d",&w[i]);
dfs(1,0);
printf("%d\n",ans);
return 0;
}
/*
3 1
1 2 2
*/