Codeforces913F. Strongly Connected Tournament
n<=2000个人参加比赛,这样比:(这里的序号没按题目的)1、两两比一场,比完连个图,边i->j表示i赢了j。2、连完那个图强联通分量缩起来,强连通分量内继续比,即强连通分量递归进行1、2,直到每个强连通分量大小为1.i<j时i有a/b的概率赢j,问每个人比赛的场数的总和的期望,答案%998244353。
n个人搞完一次会有大大小小的联通块,就可以递归下去了!但是每次可能分出很多种情况,怎么算呢?选他的一个每种图一定有的强连通分量来枚举即可,那就枚举拓扑序最后的那一个分量,也就是输给了除分量外所有人的那些人组成的,吧!$Ans_i$--i个人答案,$Ans_i=\sum_{j=1}^{i}str_j*cp_{i,j}*(\frac{j(j-1)}{2}+j(i-j)+Ans_i+Ans_{s-i})$,其中$str_i$表示i个点成强连通分量的概率,$cp_{i,j}$表示i个点中j个点输给其他所有人这件事发生的概率。注意到$Ans_i$在$j=i$时会转移到自己,移个项除个系数即可,略。而$str_i=1-\sum_{j=1}^{i-1}str_j*cp_{i,j}$,$cp_{i,j}=cp_{i-1,j-1}p^{i-j}+cp_{i-1,j}(1-p)^j,cp_{i,0}=1$。
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
//#include<assert.h>
#include<algorithm>
//#include<iostream>
using namespace std; int n,a,b,p;
#define maxn 2011
const int mod=;
int cp[maxn][maxn],str[maxn],ans[maxn]; int powmod(int a,int b)
{
int ans=;
while (b)
{
if (b&) ans=1ll*ans*a%mod;
a=1ll*a*a%mod;
b>>=;
}
return ans;
} int list1p[maxn],listp[maxn];
int main()
{
scanf("%d%d%d",&n,&a,&b); p=1ll*a*powmod(b,mod-)%mod;
cp[][]=;
list1p[]=; for (int i=;i<=n;i++) list1p[i]=list1p[i-]*1ll*(mod+-p)%mod;
listp[]=; for (int i=;i<=n;i++) listp[i]=listp[i-]*1ll*p%mod;
for (int i=;i<=n;i++)
{
cp[i][]=;
for (int j=;j<=i;j++) cp[i][j]=list1p[j]*1ll*cp[i-][j]%mod+listp[i-j]*1ll*cp[i-][j-]%mod,
cp[i][j]-=cp[i][j]>=mod?mod:;
}
str[]=;
for (int i=;i<=n;i++)
{
str[i]=;
for (int j=;j<i;j++) str[i]-=str[j]*1ll*cp[i][j]%mod,str[i]+=str[i]<?mod:;
}
ans[]=ans[]=;
for (int i=;i<=n;i++)
{
ans[i]=(str[i]*1ll*cp[i][i]%mod)*i*(i-)%mod*((mod+)>>)%mod;
for (int j=;j<i;j++) ans[i]+=str[j]*1ll*cp[i][j]%mod*(1ll*j*(j-)%mod*((mod+)>>)%mod
+1ll*j*(i-j)%mod+ans[j]+ans[i-j])%mod,ans[i]-=ans[i]>=mod?mod:;
ans[i]=1ll*ans[i]*powmod(mod+-str[i]*1ll*cp[i][i],mod-)%mod;
}
printf("%d\n",ans[n]);
return ;
}
Codeforces913F. Strongly Connected Tournament的更多相关文章
- 【CF913F】Strongly Connected Tournament 概率神题
[CF913F]Strongly Connected Tournament 题意:有n个人进行如下锦标赛: 1.所有人都和所有其他的人进行一场比赛,其中标号为i的人打赢标号为j的人(i<j)的概 ...
- 【CodeForces】913 F. Strongly Connected Tournament 概率和期望DP
[题目]F. Strongly Connected Tournament [题意]给定n个点(游戏者),每轮游戏进行下列操作: 1.每对游戏者i和j(i<j)进行一场游戏,有p的概率i赢j(反之 ...
- @codeforces - 913F@ Strongly Connected Tournament
目录 @description@ @solution@ @accepted code@ @details@ @description@ n 个选手参加了一场竞赛,这场竞赛的规则如下: 1.一开始,所有 ...
- Strongly Connected Tournament
题解: 有一个很重要的性质就是 对于一张完全强联通图来说 一定有一个强联通分量入度为0(或者出度为0) 然后就一些计数题的基本套路 https://www.cnblogs.com/onioncyc/p ...
- PTA Strongly Connected Components
Write a program to find the strongly connected components in a digraph. Format of functions: void St ...
- algorithm@ Strongly Connected Component
Strongly Connected Components A directed graph is strongly connected if there is a path between all ...
- cf475B Strongly Connected City
B. Strongly Connected City time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Strongly connected(hdu4635(强连通分量))
/* http://acm.hdu.edu.cn/showproblem.php?pid=4635 Strongly connected Time Limit: 2000/1000 MS (Java/ ...
- HDU 4635 Strongly connected (Tarjan+一点数学分析)
Strongly connected Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) ...
随机推荐
- DEV—【GridControl 按钮列无法触发点击事件解决方案】
需要在按钮列的OptionColumn属性栏中找到下面两个属性,并且改为True AllowEdit=True,AllowFocus=True.
- [转]Sorting, Filtering, and Paging with the Entity Framework in an ASP.NET MVC Application (3 of 10)
本文转自:http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/sorting-fi ...
- turn协议的工作原理
Allocate请求 客户端通过发送Allocate请求给STUN服务器,从而让STUN服务器为A用户开启一个relay端口. a) 客户端A向STUN Port发送Allocate请求(图中 ...
- Android GetTimeAgo(时间戳转换几天前,几分钟前,刚刚等)
package com.studychen.seenews.util; import android.content.Context; /** * Created by tomchen on 2/26 ...
- VB6程序中NULL注意事项
VB6中从数据库中取出栏位值进行操作,若栏位值为Null,则必须小心处理,否则极易导致程序出错退出. 通常我们从recordset中取出栏位值采用Fields方法,加上栏位名称,如 rsMoney.F ...
- 黑马程序员----java基础:String与StringBuffer及基本数据类型包装类
------- android培训.java培训.期待与您交流! ---------- java中一些基础类比如String.StringBuffer和基本数据类型包装类都是非常常见且使用非常频繁的类 ...
- 计算器Pro应用项目源码
本计算器实现了一些简单的功能,可能本身还存在一些缺陷,希望大家提建议,能够改进一下. 源码项目我已经上传到源码天堂那里了:http://code.662p.com/list/11_1.html < ...
- 虚拟机centOs Linux与Windows之间的文件传输
一.配置环境 虚拟机Linux:Fedora 9 文件传输工具:SSHSecureShellClient-3.2.9 二.实现步骤 1. 在Windows中安装文件传输工具SSHSecureShell ...
- Windows之shortcut
System key combinations CTRL+ESC: Open Start menu ALT+TAB: Switch between open programs ALT+F4: Quit ...
- 比较 String,StringBuffer,StringBuilder
1)三者在执行速度方面的比较:StringBuilder > StringBuffer > String 2)String <(StringBuffer,StringBuild ...