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 ...
随机推荐
- Deep learning深度学习的十大开源框架
Google开源了TensorFlow(GitHub),此举在深度学习领域影响巨大,因为Google在人工智能领域的研发成绩斐然,有着雄厚的人才储备,而且Google自己的Gmail和搜索引擎都在使用 ...
- ATM-简单SQL查询
use master go if exists(select * from sysDatabases where name = 'BankDB') drop database BankDB go cr ...
- margin的两个有趣现象:margin合并和margin塌陷
margin合并 当两个元素在垂直方向并列,分别设置margin值时会发生一个margin合并的现象 举个例子,有两个div,垂直并列,box1设置margin-bottom:20px,box2设置m ...
- 高通平台如何使用QPST抓DUMP
一 :确认手机状态 手机系统死机白屏后,使用USB线 连接手机和计算机.打开计算机设备管理器 ,当其中与手机相关的端口只有DIAG 口 项(9006端口)时,表明手机处于DUMP 模式,可以抓DUMP ...
- c/c++ 右值引用
c/c++ 右值引用 转自:https://www.cnblogs.com/catch/p/3500678.html 左值(lvalue)和右值(rvalue)是 c/c++ 中一个比较晦涩基础的概念 ...
- 二、selenium 安装
selenium的安装所需要的环境: 1.浏览器的安装Firefox 2.JDK的安装(Java开发基础类库)eclipse 一个开发源代码的工具 3.selenium sever 下载.网络状况监视 ...
- LeetCode算法题-Min Stack(Java实现)
这是悦乐书的第177次更新,第179篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第36题(顺位题号是155).设计一个支持push,pop,top和在恒定时间内检索最小 ...
- Java断言(Assertion)
断言(Assertion)是Java中一条语句,包含一个布尔表达式,当该布尔值为真,程序则被认为是正确的:当布尔值为假,则系统会抛出错误. 断言默认禁用的,在开发时候可开启功能,有利于纠正错误,增加可 ...
- redis学习笔记(二)-五种数据类型
string hash hget ks k hset ks k v hgetall ks hdel ks k del ks hmset ks k v k v list set zset 通用命令 快 ...
- UVA437-The Tower of Babylon(动态规划基础)
Problem UVA437-The Tower of Babylon Accept: 3648 Submit: 12532Time Limit: 3000 mSec Problem Descrip ...