codeforces#1097 D. Makoto and a Blackboard(dp+期望)
题意:现在有一个数写在黑板上,它以等概率转化为它的一个约数,可以是1,问经过k次转化后这个数的期望值
题解:如果这个数是一个素数的n次方,那么显然可以用动态规划来求这个数的答案,否则的话,就对每个素因数求答案,再相乘
参考博客:https://www.cnblogs.com/birchtree/p/10234203.html
ac代码:
#include<bits/stdc++.h>
#define ll long long
#define pa pair<int,int>
using namespace std;
const int maxn=100+10;
const int mod=1e9+7;
ll po[70],dp[10000+10][70];
int m;
ll qpow(ll x,ll n)
{
ll res=1,b=x;
while(n)
{
if(n&1)res=res*b%mod;
b=b*b%mod;
n/=2;
//cout<<<<endl;
}
return res;
}
ll solve(int a,ll b)
{
memset(dp,0,sizeof(dp));
dp[0][a]=1;
for(int i=1;i<=m;i++)
for(int j=0;j<=a;j++)
for(int k=j;k<=a;k++)
dp[i][j]=(dp[i][j]+dp[i-1][k]*po[k+1])%mod;
ll res=0;
for(int i=0;i<=a;i++)
res=(res+dp[m][i]*qpow(b,i)%mod)%mod;
return res;
}
int main()
{
ll ans=1,n;
for(int i=1;i<70;i++)
po[i]=qpow(i,mod-2);
scanf("%lld %d",&n,&m);
for(ll i=2;i*i<=n;i++)
{
if(n%i==0)
{
int k=0;
while(n%i==0)
{
//cout<<1<<endl;
k++;
n/=i;
}
ans=ans*solve(k,i)%mod;
}
}
if(n!=1)ans=ans*solve(1,n)%mod;
printf("%lld\n",ans);
return 0;
}
codeforces#1097 D. Makoto and a Blackboard(dp+期望)的更多相关文章
- CodeForces - 1097D:Makoto and a Blackboard (积性)
Makoto has a big blackboard with a positive integer n written on it. He will perform the following a ...
- codeforces1097D Makoto and a Blackboard 数学+期望dp
题目传送门 题目大意: 给出一个n和k,每次操作可以把n等概率的变成自己的某一个因数,(6可以变成1,2,3,6,并且概率相等),问经过k次操作后,期望是多少? 思路:数学和期望dp 好题好题!! ...
- CF1097D Makoto and a Blackboard(期望)
[Luogu-CF1097D] 给定 \(n,k\)一共会进行 \(k\) 次操作 , 每次操作会把 \(n\) 等概率的变成 \(n\) 的某个约数 求操作 \(k\) 次后 \(n\) 的期望是多 ...
- CF1097D Makoto and a Blackboard
题目地址:CF1097D Makoto and a Blackboard 首先考虑 \(n=p^c\) ( \(p\) 为质数)的情况,显然DP: 令 \(f_{i,j}\) 为第 \(i\) 次替换 ...
- codeforces 1097 Hello 2019
又回来了.. A - Gennady and a Card Game 好像没什么可说的了. #include<bits/stdc++.h> using namespace std; cha ...
- Codeforces 219D. Choosing Capital for Treeland (树dp)
题目链接:http://codeforces.com/contest/219/problem/D 树dp //#pragma comment(linker, "/STACK:10240000 ...
- [CodeForces - 1272D] Remove One Element 【线性dp】
[CodeForces - 1272D] Remove One Element [线性dp] 标签:题解 codeforces题解 dp 线性dp 题目描述 Time limit 2000 ms Me ...
- Codeforces 878 E. Numbers on the blackboard
Codeforces 878 E. Numbers on the blackboard 解题思路 有一种最优策略是每次选择最后面一个大于等于 \(0\) 的元素进行合并,这样做完以后相当于给这个元素乘 ...
- D Makoto and a Blackboard
Makoto and a Blackboard time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
随机推荐
- [20170612]FOR ALL COLUMNS SIZE repeat(11g).txt
[20170612]FOR ALL COLUMNS SIZE repeat(11g).txt --//昨天看了https://jonathanlewis.wordpress.com/2017/06/0 ...
- shell编程-语句(八)
if else判断语句 if语句 语法格式1: if 条件 then 语句1 语句2 ... 语句n fi 语法格式2: 常用于终端命令提示符中 if [条件]:then 语句:fi if else语 ...
- Spring入门详细教程(二)
前言 本篇紧接着spring入门详细教程(一),建议阅读本篇前,先阅读第一篇.链接如下: Spring入门详细教程(一) https://www.cnblogs.com/jichi/p/1016553 ...
- java反射笔记
反射(reflect) 1. Class对象 1.1 什么是Class对象 当JVM加载某个class文件的时候,会自动创建一个唯一的Class对象(注意:由同一个类加载器加载的class文件),这个 ...
- ini (ini-parser)配置文件解析 for donet
介绍 此ini解析库适用于mono(unity3d),donet,大小在30kb左右. 开源免费:https://github.com/rickyah/ini-parser 使用示例 engine_c ...
- Bcompare工具永久使用方法
bcompare的简介 我们在工作中会经常用到bcompare工具:合入驱动,对比原始文件等. bcompare,即Beyond Compare 是一个综合的比对工具. 可比对的对象包括纯文字档. ...
- June 4. 2018 Week 23rd Monday
Don't criticize what you can't understand. 不懂的,不要随意批判. From Bob Dylan. Don't criticize what you can' ...
- Servlet中的request与response
了解这方面的知识可以查看以下博客 https://www.cnblogs.com/zhangyinhua/p/7629221.html https://www.cnblogs.com/zhaojian ...
- Jenkins+Ansible+Gitlab自动化部署三剑客-Jenkins本地搭建
后面需要shell基础,目前没有,等有了,再更
- maven项目引入依赖之后,jar包没有自动导入报错
解决这个问题可run maven-intall 一下 ,需要在联网的情况下去下载jar包. 我这样做了一下就可以了.