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 int mod=1000000007;
 6
 7 int n,k;
 8 int dp[2001][2001];
 9
10 int main()
11 {
12     scanf("%d%d",&n,&k);
13     memset(dp,0,sizeof(dp));
14     for(int i=1; i<=n; i++)
15     {
16         dp[1][i]=1;
17     }
18     for(int i=1; i<=k; i++)
19     {
20        for(int j=1; j<=n; j++)
21        {
22            for(int s=j; s<=n; s+=j)
23            {
24                dp[i][s]+=dp[i-1][j];
25                dp[i][s]%=mod;
26            }
27        }
28     }
29     long long ans=0;
30     for(int i=1; i<=n; i++)
31     {
32         ans+=dp[k][i];
33         ans%=mod;
34     }
35     printf("%lld\n",ans);
36     return 0;
37 }

时间: 2024-12-11 16:25:03

codeforces D.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

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 414B - Mashmokh and ACM

给你长度为 l 的整数数列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 = 100

【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

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

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

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