codeforces-414B-Mashmokh and ACM
2015-11-04 14:24
316 查看
codeforces-414B-Mashmokh and ACM
[code] 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……
以下是代码:
[code]#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 1000000007 int 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; }
相关文章推荐
- YARN基本组成结构
- oracle分析函数技术详解(配上开窗函数over())----
- background-position
- Objective-C之代理设计模式小实例
- windows 进程监控 Procmon.exe
- UML学习笔记动态图之状态图和活动图
- jq动态生成二维码
- 程序猿读书
- bootstrap兼容IE8问题
- UILabel自适应高度和自动换行
- 关于class-dump在mac的下载和安装
- matlab画图函数用法,subplot,plot
- MyBatis Generator产生的Example类
- [leetcode] 96. Unique Binary Search Trees 解题报告
- 《固定资产管理》数据分析
- 移动端解决fixed和input获取焦点软键盘弹出影响定位的问题
- 前端复习-02-ajax原生以及jq和跨域方面的应用。
- 研究Xposed相关一:Xposed框架的安装
- openResty环境部署文档
- IE8以下不支持location.origin