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+数学的更多相关文章

  1. HDU 5628 Clarke and math——卷积,dp,组合

    HDU 5628 Clarke and math 本文属于一个总结了一堆做法的玩意...... 题目 简单的一个式子:给定$n,k,f(i)$,求 然后数据范围不重要,重要的是如何优化这个做法. 这个 ...

  2. HDU 5628 Clarke and math Dirichlet卷积+快速幂

    题意:bc round 72 中文题面 分析(官方题解): 如果学过Dirichlet卷积的话知道这玩意就是g(n)=(f*1^k)(n), 由于有结合律,所以我们快速幂一下1^k就行了. 当然,强行 ...

  3. 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\ ...

  4. hdu 5464 Clarke and problem dp

    Clarke and problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php ...

  5. HDU 5629 Clarke and tree dp+prufer序列

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=562 题意: 求给每个节点的度数允许的最大值,让你求k个节点能组成的不同的生成树个数. 题解: 对于n ...

  6. HDU 5675 ztr loves math (数学推导)

    ztr loves math 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/A Description ztr loves re ...

  7. hdu 5675 ztr loves math(数学技巧)

    Problem Description ztr loves research Math.One day,He thought about the "Lower Edition" o ...

  8. 【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 ...

  9. hdu 4568 Hunter 最短路+dp

    Hunter Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

随机推荐

  1. python爬虫 抓取一个网站的所有网址链接

    sklearn实战-乳腺癌细胞数据挖掘 https://study.163.com/course/introduction.htm?courseId=1005269003&utm_campai ...

  2. Java大话设计模式

    设计模式(Design Patterns) ——可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了 ...

  3. nova-api源码分析(APP的调用)

    调用APIRouter的 __call__函数 nova/wsgi.py class Router(object): def __init__(self, mapper): self.map = ma ...

  4. [C]语法, 知识点总结(二. 结构体, 类别名, static, const)

    结构体 定义: struct Student{ // 定义结构体Student, stu是创建的对象         char a[17]; // 结构体里面可以有多种不同类型的变量         ...

  5. Vue 使用 prerender-spa-plugin 添加loading

    主要配置代码: new PrerenderSPAPlugin({ staticDir: path.join(__dirname, 'dist'), routes: ['/', '/introducti ...

  6. 为什么要使用断路器Hystrix?

    为什么需要 Hystrix? 在微服务架构中,我们将业务拆分成一个个的服务,服务与服务之间可以相互调用(RPC).为了保证其高可用,单个服务又必须集群部署.由于网络原因或者自身的原因,服务并不能保证服 ...

  7. SpringMVC_HelloWorld_01

    通过配置文件的方式实现一个简单的HelloWorld. 源码 一.新建项目 1.新建动态web项目 2.命名工程springmvc-01 3.勾选"Generate web.xml depl ...

  8. Hibernate 二级缓存疑难点

    一级缓存:缓存实体 二级缓存:缓存实体 Hibernate查询缓存缓存的是查询出来的实体的部分属性结果集和实体的ID(注意这里不是实体). Hibernate查询缓存:对List起作用.但是Hiber ...

  9. re模块逐步进阶

    Windows 10家庭中文版,Python 3.6.4, 正则表达式,自己一直的水平是 知道,但不熟悉,简单的也能写,复杂的就需要看资料了,距离灵活运用还是差那么一些的. 于是,今天(180831) ...

  10. Linux 生产实习01

    Linux 生产实习01 标签(空格分隔): Linux 2018.07.02 相关软件下载地址:Linux Study 0x01. 安装 VMware Workstation VMware Work ...