纸牌游戏

2017-10-18 NOIP模拟赛

2017-10-18 NOIP模拟赛

 

2017-10-18 NOIP模拟赛

 

#include<iostream>
#include<cstdio>
#include<ctime>
#include<cstdlib>
#define maxn 301
using namespace std;
int n,a[maxn],q[maxn],cnt[maxn];
long long sz[maxn];
bool vis[maxn];
int gcd(int x,int y){
    if(y==0)return x;
    else return gcd(y,x%y);
}
void dfs(int pos,int now){
    if(clock()>=980){
        puts("0.000000000 1.000000000");
        exit(0);
    }
    if(now==1){
        if((pos&1)==0)cnt[pos]++;
        return;
    }
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            vis[i]=1;
            dfs(pos+1,gcd(now,a[i]));
            vis[i]=0;
        }
    }
}
int main(){
    //freopen("Cola.txt","r",stdin);
    freopen("cards.in","r",stdin);freopen("cards.out","w",stdout);
    scanf("%d",&n);
    sz[1]=n;
    for(int i=2;i<=n;i++)sz[i]=sz[i-1]*(n-i+1);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    dfs(0,0);
    double ans=0;
    for(int i=2;i<=n;i+=2)
        ans+=(double)cnt[i]/(double)sz[i];
    printf("%.9lf ",ans);
    puts("1.000000000");
}
64分 dfs+输出1

相关文章:

  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2021-10-24
  • 2022-12-23
  • 2021-10-05
  • 2021-10-02
  • 2021-11-11
猜你喜欢
  • 2021-12-12
  • 2021-12-19
  • 2022-01-28
  • 2022-12-23
  • 2022-12-23
  • 2021-10-04
  • 2022-12-23
相关资源
相似解决方案