codeforces-414B-Mashmokh and ACM
来源:互联网 发布:风力预报软件 编辑:程序博客网 时间:2024/05/16 17:11
codeforces-414B-Mashmokh and ACM
time limit per test1 second memory limit per test256 megabytes
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 tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn’t able to solve them. That’s why he asked you to help him with these tasks. One of these tasks is the following.
A sequence of l integers b1, b2, …, bl (1 ≤ b1 ≤ b2 ≤ … ≤ bl ≤ n) is called good if each number divides (without a remainder) by the next number in the sequence. More formally for all i (1 ≤ i ≤ l - 1).
Given n and k find the number of good sequences of length k. As the answer can be rather large print it modulo 1000000007 (109 + 7).
Input
The first line of input contains two space-separated integers n, k (1 ≤ n, k ≤ 2000).
Output
Output a single integer — the number of good sequences of length k modulo 1000000007 (109 + 7).
input
3 2
output
5
input
6 4
output
39
input
2 1
output
2
Note
In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3].
题目链接:cf-414B
题目大意:问在1~n中有多少个序列满足后一项能整除前一项。
题目思路:dp。dp[i][j] 表示在1~i中,序列以j结尾有多少种方法数满足条件。
以 1,2,3,4,5为例。
长度为1:[1],[2],[3],[4],[5]
长度为2:[1,1],[1,2],[1,3],[1,4],[1,5],[2,2],[2,4],[3,3],[4,4][5,5]。
长度为3……
以下是代码:
#include <vector>#include <map>#include <set>#include <algorithm>#include <iostream>#include <cstdio>#include <cmath>#include <cstdlib>#include <string>#include <cstring>using namespace std;#define MOD 1000000007int dp[3000][3000];int main(){ int n,k; cin >> n >> k; for (int i = 0; i <= n; i++) //初始化,长度为1,以i结尾的方法数为1 dp[1][i] = 1; for (int i = 1; i < k; i++) //遍历序列长度 { for (int j = 1; j <= n; j++) //以j结尾 { for (int m = j; m <= n; m += j) { dp[i + 1][m] = (dp[i + 1][m] + dp[i][j]) % MOD; } } } long long ans = 0; for (int i = 1; i <= n; i++) { ans = (ans + dp[k][i]) % MOD; } cout << ans << endl; return 0;}
- CodeForces 414B--Mashmokh and ACM (dp)
- Mashmokh and ACM - CodeForces 414B dp
- codeforces 414B Mashmokh and ACM
- codeforces--414B--Mashmokh and ACM
- codeforces-414B-Mashmokh and ACM
- Codeforces 414b Mashmokh and ACM
- codeforces 414B B. Mashmokh and ACM(dp)
- Codeforces 414b Mashmokh and ACM(简单DP)
- CodeForces 414B Mashmokh and ACM dp + 决策总数
- CodeForces 414B Mashmokh and ACM (DP)
- Codeforces 414B Mashmokh and ACM(DP)
- Codeforces#414B——Mashmokh and ACM
- Codeforces 414B Mashmokh and ACM【预处理+dp】
- B. Mashmokh and ACM
- B. Mashmokh and ACM
- Codeforces 414A Mashmokh and ACM(dp)
- Codeforce--414B--Mashmokh and ACM
- CF 414B Mashmokh and ACM
- UVa 12704 - Little Masters
- UML学习笔记之构件图和部署图
- 让linux Sort 按照 ASCII 顺序排序
- oracle分析函数技术详解(配上开窗函数over())----
- 如何在java Web项目中开发WebService接口
- codeforces-414B-Mashmokh and ACM
- Notepad++ 运行java
- JVM系列一:JVM内存组成及分配
- YARN基本组成结构
- linux 内核链表
- cocos2d-x中spine骨骼动画的应用
- HTTP请求头具体含意
- jquery选取除了div之后 含有类名为a的 标签
- 学习嵌入式Linux-JZ2440-U-Boot简介