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 ...
随机推荐
- shell编程-输入/输出重定向(十一)
linux中文件描述符 linux跟踪打开文件,而分配的一个数字,通过这个数字可以实现对文件的读写操作 用户可以自定义文件描述符范围是:3-max,max跟用户的ulimit –n 定义数字有关系,不 ...
- 在Lua中提示UnityEngine.dll的方法
我的环境 安装最新的 EmmyLua-1.2.1及以上版本 IDEA 2017.1.2 及以上版本 关于EmmlyLua的介绍可查看我之前的文章:Lua代码提示和方法跳转 说明:本文方法摘自 Emmy ...
- python列表与元组的用法
python列表与元组的用法 目录: 列表的用法: 1.增 append + extend 2.删 del remove 3.改 insert 4.查 index 5.反向 ...
- PHP中判断变量是否存在的方式
isset()函数判断变量是否设置. thinkPHP中判断select查询时返回值是否为空 $object->isEmpty() empty():当变量存在,并且是一个非空非零的值时,返回 ...
- 第十四届智能车队员培训 I/O的使用 数据方向寄存器和数据寄存器的配置 MC9S12D64处理器
I/O的使用 数据方向寄存器和数据寄存器的配置 I/O输入输出的使用: 数据方向寄存器与数据寄存器 寄存器的概念: 寄存器,是集成电路中非常重要的一种存储单元,通常由触发器组成.在集成电路设计中,寄存 ...
- ACDSee清除旧版本残余
新建记事本,输入以下内容: reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\ACD Systems" /f reg delete "HKE ...
- Eric Chen Mock Interview
Given an array with integers. Find two non-overlapping subarrays A and B, which |SUM(A) - SUM(B)| is ...
- 《Java大学教程》—第5章 数组
5.6 增强的for循环:访问整个数组,读取数组元素,不基于数据下列5.7 数组方法:最大值.求和.成员访问.查找 1.答:P92存储固定个数相同数据类型的一组元素. 2.答:P92所有存储在一个特定 ...
- MySQL高级知识(六)——索引优化
前言:索引优化的目的主要是让索引不失效,本篇通过相关案例对索引优化进行讲解. 0.准备 创建经典的tb_emp表. DROP TABLE IF EXISTS `tb_emp`; CREATE TABL ...
- tomcat 设置连接数
maxConnections.maxThreads.acceptCount的含义及关系maxThreads:tomcat同时处理请求的任务个数,默认值为200maxConnections :tomca ...