社区讨论
82分,TLE
P3154[CQOI2009] 循环赛参与者 4已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @mi7p8ixi
- 此快照首次捕获于
- 2025/11/21 01:22 4 个月前
- 此快照最后确认于
- 2025/11/21 01:22 4 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
struct node
{
int a,b;
}match[10000];
int k,n;
int shizhanying=0;
int ans=0;
long long last[10000];
int score[30]={0};
int check()
{
for(int i=1;i<=n;i++)
{
if(last[i]!=score[i])return 1;
}
return 0;
}
void dfs(int i,int d)
{
if(i==k+1){if(check()==0){ans++;}return;}
if((k-i+1)<(shizhanying-d))return;
score[match[i].a]+=3;
if(score[match[i].a]<=last[match[i].a]){dfs(i+1,d);}
score[match[i].a]-=3;
score[match[i].b]+=3;
if(score[match[i].b]<=last[match[i].b]){dfs(i+1,d);}
score[match[i].b]-=3;
if(d<shizhanying)
{
score[match[i].a]+=1;
score[match[i].b]+=1;
if(score[match[i].a]<=last[match[i].a]&&score[match[i].b]<=last[match[i].b])
{
dfs(i+1,d+1);
}
score[match[i].a]-=1;
score[match[i].b]-=1;
}
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>last[i];
}
int sum=0;
for(int i=1;i<=n;i++)
{
sum+=last[i];
}
k=n*(n-1)>>1;
int ssr=k+(k<<1);
shizhanying=ssr-sum;
int tamp=1;
for(int i=1;i<n;i++)
{
for(int j=i+1;j<=n;j++)
{
match[tamp].a=i;
match[tamp].b=j;
tamp++;
}
}
dfs(1,0);
cout<<ans;
return 0;
}
回复
共 3 条回复,欢迎继续交流。
正在加载回复...