CodeForces 414B - Mashmokh and ACM

给你长度为 的整数数列b1, b2, ..., bl(1 ≤ b1 ≤ b2 ≤ ... ≤ bl ≤ n)

如果这个数列被称为好的,那么每个元素都可以整除下一个元素

给你n和k,去找到长度为k的好数列的个数

dp[任意i][1] = 1;

dp[i的倍数][长度k] = dp[i][长度k-1] + 1;

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 const int MOD = 1000000007 ;
 5 int n,k;
 6 long long dp[2005][2005]={0};
 7 int main()
 8 {
 9     scanf("%d%d",&n,&k);
10     for(int i = 1;i <= n; i++)
11     {
12         dp[i][1] = 1;
13         for(int j = i;j<=n; j+= i)
14         {
15             for(int v = 2 ;v<=k;v++)
16             {
17                 dp[j][v] +=dp[i][v-1];
18                 if(dp[j][v]>=MOD) dp[j][v] -= MOD;
19             }
20         }
21     }
22     long long sum=0;
23     for(int i = 1;i <= n ; i++)
24     {
25         sum += dp[i][k];
26         if(sum>MOD) sum -= MOD;
27     }
28     printf("%I64d\n",sum);
29 }
时间: 2024-12-16 23:48:43

CodeForces 414B - Mashmokh and ACM的相关文章

Codeforces 414B Mashmokh and ACM(DP)

Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tas

cf 414B Mashmokh and ACM 动态规划

题目链接:http://codeforces.com/problemset/problem/414/B dp[i][j]表示长度为i.最后一个数字为j的合法序列总数 dp[1][1...2000]都是1 后面用dp[i-1][j] 去更新 dp[i][j*t] (1 <= j*t <= 2000) 即用因子去更新它的倍数 表面上看是2000^3的复杂度会爆 其实不用算那么多次 最外层循环是2000 分析第二层和第三层 需要算 2000/1 + 2000/2 + 2000/3 + 2000/4

CodeForces 415D Mashmokh and ACM

$dp$. 记$dp[i][j]$表示已经放了$i$个数字,并且第$i$个数字放了$j$的方案数.那么$dp[i][j] = \sum\limits_{k|j}^{}  {dp[i - 1][k]}$ #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorit

codeforces D.Mashmokh and ACM

题意:给你n和k,然后找出b1, b2, ..., bl(1 ≤ b1 ≤ b2 ≤ ... ≤ bl ≤ n),并且对所有的bi+1%bi==0,问有多少这样的序列? 思路:dp[i][j] 表示长度为i,以j为结尾有多少.dp[i][j]+=dp[i-1][s],j%s==0; 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 const

codeforces 414B B. Mashmokh and ACM(dp)

题目链接: codeforces 414B 题目大意: 定义一个序列,前一项能够整除后一项,给定这个序列中数的取值范围和序列的长度,问有多少种构造方法. 题目分析: 我们定义状态dp[i][j]为前i项已经确定且第i项为j的方案数. 转移方程 dp[i][j]=∑k|jdp[i?1][k] 复杂度O(n?k) AC代码: #include <iostream> #include <cstring> #include <algorithm> #include <cs

【codeforces 415D】Mashmokh and ACM(普通dp)

[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=2000),问满足[数列长度是k && 数列中每一个元素arr[i]在1~n之间 && 数列中元素可以重复]的数列有多少个?结果对10^9+7取余 解题思路:dp[i][j]表示长度是j,最后一位是i的种数 if(kk%i==0) dp[kk][j+1]+=dp[i][j] 1 #i

Codeforces Round #240 (Div. 1)---B.Mashmokh and ACM(dp)

Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tas

Mashmokh and ACM CodeForces - 414D (贪心)

大意: 给定n结点树, 有k桶水, p块钱, 初始可以任选不超过k个点(不能选根结点), 在每个点放一桶水, 然后开始游戏. 游戏每一轮开始时, 可以任选若干个节点关闭, 花费为关闭结点储存水的数量和, 然后未关闭的非根结点上的水会流入父结点, 然后再开始新的一轮. 当所有非根结点无水后游戏结束, 假设第$i$轮流入根节点的水为$w_i$, 游戏共进行了$l$轮, 求$max(w_1,w_2,...,w_l)$ 可以发现最优时一定是一段深度相邻的水, 所以双指针维护一段连续的区间就行了. 考虑每

CodeForces - 415B Mashmokh and Tokens

Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens b