HDU 5628 Clarke and math dp+数学
Clarke and math
题目连接:
http://acm.hdu.edu.cn/showproblem.php?pid=5628
Description
Clarke is a patient with multiple personality disorder. One day, he turned into a mathematician, did a research on interesting things.
Suddenly he found a interesting formula. Given f(i),1≤i≤n, calculate
g(i)=∑i1∣i∑i2∣i1∑i3∣i2⋯∑ik∣ik−1f(ik) mod 1000000007(1≤i≤n)
Input
The first line contains an integer T(1≤T≤5), the number of test cases.
For each test case, the first line contains two integers n,k(1≤n,k≤100000).
The second line contains n integers, the ith integer denotes f(i),0≤f(i)<109+7.
Output
For each test case, print a line contained n integers, the ith integer represents g(i).
Sample Input
2
6 2
2 3 3 3 3 3
23 3
2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
Sample Output
2 7 7 15 7 23
2 9 9 24 9 39 9 50 24 39 9 102 9 39 39 90 9 102 9 102 39 39 9
Hint
题意
题解:
dp
dp[i][j]表示第i位置,选择了j个不同的因子之后,能够获得的权值是多少
ans[i]=sigma C(k,j)*dp[i][j]
为什么呢?
我们考虑传递了k次的sigma,实际上就是在枚举因子,在这个数据范围内,最多枚举20个不同的因子,而且因子显然是不断递减的(当然,这句话没什么用
然后脑补脑补,这个就是对的了……
官方题解确实看不懂……
弱智选手并不会xx卷积……
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
const int mod = 1e9+7;
long long fac[maxn];
long long qpow(long long a,long long b)
{
long long ans=1;a%=mod;
for(long long i=b;i;i>>=1,a=a*a%mod)
if(i&1)ans=ans*a%mod;
return ans;
}
long long C(long long n,long long m)
{
if(m>n||m<0)return 0;
long long s1=fac[n],s2=fac[n-m]*fac[m]%mod;
return s1*qpow(s2,mod-2)%mod;
}
int a[maxn];
int dp[maxn][22];
int K=20;
int main()
{
fac[0]=1;
for(int i=1;i<maxn;i++)
fac[i]=fac[i-1]*i%mod;
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
memset(dp,0,sizeof(dp));
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
dp[i][0]=a[i];
for(int i=1;i<=n;i++)
for(int j=i+i;j<=n;j+=i)
for(int k=0;k<K;k++)
dp[j][k+1]=(dp[j][k+1]+dp[i][k])%mod;
for(int i=1;i<=n;i++)
{
int ans = 0;
for(int j=0;j<=K;j++)
ans=(ans+1ll*C(m,j)*dp[i][j])%mod;
if(i==n)printf("%d",ans);else printf("%d ",ans);
}
printf("\n");
}
}
HDU 5628 Clarke and math dp+数学的更多相关文章
- HDU 5628 Clarke and math——卷积,dp,组合
HDU 5628 Clarke and math 本文属于一个总结了一堆做法的玩意...... 题目 简单的一个式子:给定$n,k,f(i)$,求 然后数据范围不重要,重要的是如何优化这个做法. 这个 ...
- HDU 5628 Clarke and math Dirichlet卷积+快速幂
题意:bc round 72 中文题面 分析(官方题解): 如果学过Dirichlet卷积的话知道这玩意就是g(n)=(f*1^k)(n), 由于有结合律,所以我们快速幂一下1^k就行了. 当然,强行 ...
- HDU.5628.Clarke and math(狄利克雷卷积 快速幂)
\(Description\) \[g(i)=\sum_{i_1|i}\sum_{i_2|i_1}\sum_{i_3|i_2}\cdots\sum_{i_k|i_{k-1}}f(i_k)\ mod\ ...
- hdu 5464 Clarke and problem dp
Clarke and problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php ...
- HDU 5629 Clarke and tree dp+prufer序列
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=562 题意: 求给每个节点的度数允许的最大值,让你求k个节点能组成的不同的生成树个数. 题解: 对于n ...
- HDU 5675 ztr loves math (数学推导)
ztr loves math 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/A Description ztr loves re ...
- hdu 5675 ztr loves math(数学技巧)
Problem Description ztr loves research Math.One day,He thought about the "Lower Edition" o ...
- 【hdu 5628】Clarke and math (Dirichlet卷积)
hdu 5628 Clarke and math 题意 Given f(i),1≤i≤n, calculate \(\displaystyle g(i) = \sum_{i_1 \mid i} \su ...
- hdu 4568 Hunter 最短路+dp
Hunter Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
随机推荐
- Vue实例的生命周期(钩子函数)
Vue实例的生命钩子总共有10个 先上官方图: 下面时一个vue实例定义钩子函数的例子: var app=new Vue({ el:'#app', beforeCreate:function(){ c ...
- Why is my Spring @Autowired field null?
spring有@Autowired 空指针异常 https://stackoverflow.com/questions/19896870/why-is-my-spring-autowired-fiel ...
- argunlar 1.0.1 【数据绑定】
<!DOCTYPE html><html lang="en" ng-app><head> <meta charset="U ...
- 【51Nod】1920 空间统计学 状压DP
[题目]1920 空间统计学 [题意]给定m维空间中的n个点坐标,满足每一维坐标大小都在[0,3]之间,现在对于[0,3*m]的每个数字x统计曼哈顿距离为x的有序点对数.\(n \leq 2*10^5 ...
- 【51Nod】1273 旅行计划 树上贪心
[题目]51Nod 1273 旅行计划 [题意]给定n个点的树和出发点k,要求每次选择一个目的地旅行后返回,使得路径上未访问过的点最多(相同取编号最小),旅行后路径上所有点视为访问过,求旅行方案.\( ...
- pt-table-checksum 3.0.4检测不出主从差异数据
群里好几位同学问 pt-table-checksum 3.0.4, 主从两个表数据是不一致,为啥检测不出来?前段时间自己也测试过,只是没整理成随笔^_- 一.基本环境 VMware10.0+CentO ...
- 以后的博客将更新到自己的域名pythonsite.com,欢迎访问
以后的博客将更新到自己的域名pythonsite.com,欢迎访问
- innodb和myisam数据库文件存储详解以及mysql表空间
数据库常用的两种引擎有Innodb和Myisam,关于二者的区别参考:https://www.cnblogs.com/qlqwjy/p/7965460.html 1.关于数据库的存储在两种引擎的存储是 ...
- 更改jupyter notebook的主题颜色(theme) 包括pycharm
https://blog.csdn.net/Techmonster/article/details/73382535
- vue项目使用vw单位适配移动端方法
传送门: https://blog.csdn.net/zjw0742/article/details/79337336