Codeforces Round #407 (Div. 2), problem: (E) The Great Mixing Solution in C

#include<bits/stdc++.h>
using namespace std;
int n,k,f[1005];
bitset<2001> dp[2];
int main()
{
cin>>n>>k;
for(int i=1,t;i<=k;i++)
{
scanf(“%d”,&t);
f[t]=1;
}
dp[0][1000]=1;
int now=0;
for(int i=1;i<=1000;i++)
{
now^=1;
dp[now].reset();
for(int j=0;j<=1000;j++)
if(f[j])dp[now]|=(dp[now^1]<<j)>>n;
if(dp[now][1000])
{
return 0*printf(“%d\n”,i);

}
}
puts(“-1”);
return 0;
}

(Visited 58 times, 1 visits today)

About the Author:

Leave A Comment