What is the CodeForces Round 2023 competition about?

2026-06-10 04:371阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计270个文字,预计阅读时间需要2分钟。

What is the CodeForces Round 2023 competition about?

由于最多24个数字...可以表示所有存在的状态...然后DP更新就是...某些卡片时间..+Program:

What is the CodeForces Round 2023 competition about?


因为最多24个数...可以用2^24表示所有的存在情况...然后DP更新就是..有些卡时间..


Program:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<set>
#include<algorithm>
#include<cmath>
#define oo 1000000007
#define ll long long
#define pi acos(-1.0)
#define MAXN 505
using namespace std;
int n,m,a[26],b[3];
ll dp[17000000],t;
int main()
{
int i,x,p,sum,need;
while (~scanf("%d",&n))
{
for (i=1;i<=n;i++) scanf("%d",&a[i]);
scanf("%d",&m);
for (i=1;i<=m;i++) scanf("%d",&b[i]);
dp[0]=1;
need=(1<<n)-1;
for (x=1;x<=need;x++)
{
p=x;
t=sum=i=0;
while (p)
{
if (p%2)
{
t+=dp[x&(~(1<<i))];
sum+=a[i+1];
}
i++,p>>=1;
}
for (i=1;i<=m;i++)
if (sum==b[i]) t=0;
dp[x]=t%oo;
}
printf("%I64d\n",dp[need]);
}
return 0;
}



本文共计270个文字,预计阅读时间需要2分钟。

What is the CodeForces Round 2023 competition about?

由于最多24个数字...可以表示所有存在的状态...然后DP更新就是...某些卡片时间..+Program:

What is the CodeForces Round 2023 competition about?


因为最多24个数...可以用2^24表示所有的存在情况...然后DP更新就是..有些卡时间..


Program:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<set>
#include<algorithm>
#include<cmath>
#define oo 1000000007
#define ll long long
#define pi acos(-1.0)
#define MAXN 505
using namespace std;
int n,m,a[26],b[3];
ll dp[17000000],t;
int main()
{
int i,x,p,sum,need;
while (~scanf("%d",&n))
{
for (i=1;i<=n;i++) scanf("%d",&a[i]);
scanf("%d",&m);
for (i=1;i<=m;i++) scanf("%d",&b[i]);
dp[0]=1;
need=(1<<n)-1;
for (x=1;x<=need;x++)
{
p=x;
t=sum=i=0;
while (p)
{
if (p%2)
{
t+=dp[x&(~(1<<i))];
sum+=a[i+1];
}
i++,p>>=1;
}
for (i=1;i<=m;i++)
if (sum==b[i]) t=0;
dp[x]=t%oo;
}
printf("%I64d\n",dp[need]);
}
return 0;
}