Codeforces 1139D Steps to One dp
啊, 我要死了, 这种垃圾题居然没写出来, 最后十分钟才发现错在哪。
不知道为什么我以为 对于一个数x , 除了它的因子和它的倍数都是和它互质的, 我脑子是抽了吗?
随便瞎dpdp的题。。 还熬夜打cf好暴躁啊啊啊。
我求我自己以后打比赛多动动脑子。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ;
const double eps = 1e-;
const double PI = acos(-); int Power(int a, int b) {
int ans = ;
while(b) {
if(b & ) ans = 1ll * ans * a % mod;
a = 1ll * a * a % mod; b >>= ;
}
return ans;
}
void add(int &a, int b) {
a += b; if(a >= mod) a -= mod;
} int n, ans, dp[N];
int inv[N]; vector<int> fac[N];
vector<int> cnt[N]; int dfs(int x) {
if(x == ) return ;
if(~dp[x]) return dp[x];
dp[x] = ;
int ret = n / x;
int res = SZ(fac[x]);
add(dp[x], (1ll * inv[n - ret] * n + mod) % mod);
for(int i = ; i < SZ(fac[x]) - ; i++) {
add(dp[x], 1ll * inv[n - ret] * cnt[x][i] % mod * dfs(fac[x][i]) % mod);
}
return dp[x];
} int main() {
memset(dp, -, sizeof(dp));
inv[] = ;
for(int i = ; i < N; i++) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
for(int i = ; i < N; i++)
for(int j = i; j < N; j += i)
fac[j].push_back(i);
scanf("%d", &n);
for(int i = ; i <= n; i++) {
cnt[i].resize(SZ(fac[i]));
for(int j = SZ(fac[i]) - ; j >= ; j--) {
cnt[i][j] = n / fac[i][j];
for(int k = j + ; k < SZ(fac[i]); k++)
if(fac[i][k] % fac[i][j] == )
cnt[i][j] -= cnt[i][k];
}
}
for(int i = ; i <= n; i++)
add(ans, 1ll * inv[n] * dfs(i) % mod);
printf("%d\n", ans);
return ;
} /*
*/
Codeforces 1139D Steps to One dp的更多相关文章
- Codeforces.1139D.Steps to One(DP 莫比乌斯反演)
题目链接 啊啊啊我在干什么啊.怎么这么颓一道题做这么久.. 又记错莫比乌斯反演式子了(╯‵□′)╯︵┻━┻ \(Description\) 给定\(n\).有一个初始为空的集合\(S\).令\(g\) ...
- codeforces#1139D. Steps to One (概率dp+莫比乌斯反演)
题目链接: http://codeforces.com/contest/1139/problem/D 题意: 在$1$到$m$中选择一个数,加入到一个初始为空的序列中,当序列的$gcd$和为$1$时, ...
- Codeforces - 1139D - Steps to One (概率DP+莫比乌斯反演)
蒟蒻数学渣呀,根本不会做. 解法是参考 https://blog.csdn.net/xs18952904/article/details/88785210 这位大佬的. 状态的设计和转移如上面博客一样 ...
- [Codeforces 1139D] Steps to One
[题目链接] https://codeforces.com/contest/1139/problem/D [算法] 考虑dp 设fi表示现在gcd为i , 期望多少次gcd变为1 显然 , fi = ...
- Codeforces 1139D(推式子+dp)
题目传送 推公式博客传送 推完式子就是去朴素地求就行了Orz const int maxn = 1e5 + 5; const int mod = 1e9 + 7; int m, mu[maxn], v ...
- [BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆)
[BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆) 题面 一棵二叉树的所有点的点权都是给定的集合中的一个数. 让你求出1到m中所有权 ...
- Codeforces Round #321 (Div. 2) A. Kefa and First Steps【暴力/dp/最长不递减子序列】
A. Kefa and First Steps time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces 1139D(期望dp)
题意是模拟一个循环,一开始有一个空序列,之后每次循环: 1.从1到m中随机选出一个数字添加进去,每个数字被选的概率相同. 2.检查这个序列的gcd是否为1,如果为1则停止,若否则重复1操作直至gcd为 ...
- codeforces 721C (拓排 + DP)
题目链接:http://codeforces.com/contest/721/problem/C 题意:从1走到n,问在时间T内最多经过多少个点,按路径顺序输出. 思路:比赛的时候只想到拓排然后就不知 ...
随机推荐
- 【原创】Linux基础之gz文件相关操作
gz文件不需要解压即可进行相关操作 $ zcat test.log.gz $ zmore test.log.gz $ zless test.log.gz $ zgrep '1.2.3.4' test. ...
- Mvc 批量图片上传
首先导入文件(官网上下载 kindeditor ): <link href="~/kindeditor-4.1.11-zh-CN/kindeditor/themes/default/d ...
- 6)协程三( asyncio处理并发)
一:使用 asyncio处理并发 介绍 asyncio 包,这个包使用事件循环驱动的协程实现并发.这是 Python 中最大也是最具雄心壮志的库之一. 二:示例 1)单任务协程处理和普通任务比较 #普 ...
- 分享一份非常强势的Android面试题
马上步入金九银十了,是时候看一些面试题去鹅厂了,接下来我将分享一些面试题,每天总结一点点,希望对大家有所帮助! ListView和RecyclerView区别 参考链接: https://blog.c ...
- STM32L476应用开发之一:初次使用
今天终于收到了期待已久的NUCLEO-F412ZG,感谢电子发烧友论坛!多年以来基本都是在STM32平台上做一些设计开发工作.但是低功耗的基本没用过,这次要做便携式设备才对这方面有所接触,正好这时电子 ...
- 后RCNN时代的物体检测及实例分割进展
https://mp.weixin.qq.com/s?__biz=MzA3MzI4MjgzMw==&mid=2650736740&idx=3&sn=cdce446703e69b ...
- javaScript遍历对象、数组总结
javaScript遍历对象总结 1.使用Object.keys()遍历 返回一个数组,包括对象自身的(不含继承的)所有可枚举属性(不含Symbol属性). var obj = {'0':'a ...
- day10 函数2
为什么需要函数? 先使用目前的知识点实现一个需求: """ 三个功能 1.登录 2.购物车 3.收藏夹 收藏夹和 购物车 需要先登录才能使用! ...
- Memcached简介及环境安装
Memcached简介及环境安装 author:SimpleWu 简介 Memcached是一个自由开源的,高性能,分布式内存对象缓存系统. Memcached是以LiveJournal旗下Danga ...
- bzoj 1222
比较简单的背包dp,设计状态f[i][j]表示到了前i个物品,第一台机器加工时间为j,第二台机器加工所用的最小时间,然后背包转移即可 本题卡空间,需要滚动数组优化 本题卡时间,稍微卡下常就行 #inc ...