/ Randle /

记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 3ms 384.0 KiB
#2 Accepted 3ms 512.0 KiB
#3 Accepted 4ms 480.0 KiB
#4 Accepted 4ms 384.0 KiB
#5 Accepted 6ms 400.0 KiB
#6 Accepted 15ms 512.0 KiB
#7 Accepted 11ms 480.0 KiB
#8 Accepted 5ms 384.0 KiB
#9 Accepted 6ms 480.0 KiB
#10 Accepted 4ms 472.0 KiB

代码

#include <stdio.h>
#include <iostream>
#include <cstring>
const int maxn = 105;
using namespace std;
int a[maxn];
double dp[maxn];
double g[maxn][maxn];
double quick[maxn];
double mem[maxn][maxn];
inline double ccc(int n,int m) {
    if(mem[n][m]<=1e-9) {
        if(m==0) return quick[n];
        if(n==m) {
            return quick[n];
        }
        double ret = ccc(n-1,m)*1.0/2.0+ccc(n-1,m-1)*1.0/2.0;
        mem[n][m] = ret;
        return ret;
    }else{
        return mem[n][m];
    }
}
int main() {
    memset(mem,0,sizeof(mem));
    int n,c,k;
    cin>>n>>c>>k;
    for(int i = 1; i<=k; i++) {
        int x,y;
        cin>>x>>y;
        for(int i = x; i<=y; i++) a[i]++;
    }
    quick[0] = 1;
    quick[1] = 1.0/2.0;
    for(int i = 2; i<=k; i++) {
        quick[i] = quick[i-1]*1.0/2.0;
    }
    g[0][1] = 1;
    for (int i=0; i<=k; ++i)
        for (int j=0; j<c; ++j)
            for (int k=0; k<c; ++k) g[i+1][j*k%c] += g[i][j]/c;

    for(int i = 1; i<=k; i++) {
        double z = 1;
        if(a[i]) z += a[i];
    }
    double ans = 0;
    for(int i  = 1; i<=n; i++) {
        for(int j = 0; j<=a[i]; j++) {
            double ck = ccc(a[i],j);
            for(int z = 0; z<c; z++) {
                ans+=ck*g[j][z]*z;
            }
        }
    }
    printf("%.3lf",ans);
    return 0;
}

信息

递交者
类型
递交
题目
灵魂画师T2
题目数据
下载
语言
C++
递交时间
2017-11-07 14:36:00
评测时间
2017-11-07 14:36:00
评测机
分数
100
总耗时
65ms
峰值内存
512.0 KiB