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 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).

Sample test(s)

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].

dp[i][j]表示长度为i,第i个数为j的方案数

/*************************************************************************
    > File Name: cf-240-div1-B.cpp
    > Author: ALex
    > Mail: [email protected]
    > Created Time: 2015年06月02日 星期二 12时35分58秒
 ************************************************************************/

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#include <set>
#include <vector>

using namespace std;

const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;

static const int mod = 1000000007;
LL dp[2010][2010];

int main() {
    int n, k;
    while (cin >> n >> k) {
        memset(dp, 0, sizeof(dp));
        for (int i = 1; i <= n; ++i) {
            dp[1][i] = 1;
        }
        for (int i = 1; i < k; ++i) {
            for (int j = 1; j <= n; ++j) {
                if (!dp[i][j]) {
                    continue;
                }
                for (int l = j; l <= n; l +=j) {
                    dp[i + 1][l] += dp[i][j];
                    dp[i + 1][l] %= mod;
                }
            }
        }
        LL ans = 0;
        for (int i = 1; i <= n; ++i) {
            ans += dp[k][i];
            ans %= mod;
        }
        cout << ans << endl;
    }
    return 0;
}
时间: 2024-11-06 09:57:18

Codeforces Round #240 (Div. 1)---B.Mashmokh and ACM(dp)的相关文章

Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister(DP)

题目链接:Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister 题意: 有n层楼,每层有m个房间,每层的两边是楼梯. 现在有一个人站在左下角,这个人必须将这一层的灯关闭后才能去另外一层. 每移动一次需要1分钟,问关闭所有灯需要多少时间. 题解: 考虑DP[i][j]表示当前已经关闭了第i层全部的灯,j=0时表示在这一层的最左边,j=1时表示在这一层的最右边. 然后推上去就行了.最后讨论一下特殊情况. 1 #include<bits/

Codeforces Round #360 (Div. 2) D 数学推导 E dp

Codeforces Round #360 (Div. 2) A  == B  水,但记一下: 第 n 个长度为偶数的回文数是  n+reverse(n). C    dfs 01染色,水 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i

Codeforces Round #240 (Div. 2) (ABCDE题解)

题目链接:http://codeforces.com/contest/415 A. Mashmokh and Lights time limit per test:1 second memory limit per test:256 megabytes Mashmokh works in a factory. At the end of each day he must turn off all of the lights. The lights on the factory are index

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 Round #245 (Div. 1) B. Working out (简单DP)

题目链接:http://codeforces.com/problemset/problem/429/B 给你一个矩阵,一个人从(1, 1) ->(n, m),只能向下或者向右: 一个人从(n, 1) ->(1, m),只能向上或者向右.必须有一个相遇点, 相遇点的值不能被取到, 问两个人能得到的最大路径和是多少? dp[i][j]:表示从一个点出发的最大值:先预处理从(1,1) (1,m) (n,1) (n,m)四个点出发的4个dp最大值.然后枚举所有的点,但是这个点不能在边缘,考虑枚举点不够

Codeforces Round #168 (Div. 1) B. Zero Tree 树形dp

题目链接: http://codeforces.com/problemset/problem/274/B 题意: 给出一棵树,每个点有权值,每次操作可以对一个联通子集中的点全部加1,或者全部减1,且每次操作必须包含点1,问最少通过多少次操作可以让整棵树每个点的权值变为0. 思路: http://blog.csdn.net/qq_24451605/article/details/48622953 定义状态up[u],down[u]代表点u被加操作的次数和点u被减操作的次数 因为必须包含点1,所以我

Codeforces Round #221 (Div. 1) B. Maximum Submatrix 2 dp排序

B. Maximum Submatrix 2 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/375/B Description You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is

Codeforces Round #336 (Div. 2) D. Zuma(区间DP)

题目链接:https://codeforces.com/contest/608/problem/D 题意:给出n个宝石的颜色ci,现在有一个操作,就是子串的颜色是回文串的区间可以通过一次操作消去,问最少需要多少次操作可以消除所有的宝石.(每次操作消除一个回文串,最少操作次数清楚字符串) 题解:dp[l][r]表示区间(l,r)的最少操作次数,对于一个区间(l,r),有两种转移:①若存在c_l = c_i(l <= i <= r),可以由dp[l][i] + dp[i + 1][r]转移:②若c

Codeforces Round #530 (Div. 2)F Cookies (树形dp+线段树)

题:https://codeforces.com/contest/1099/problem/F 题意:给定一个树,每个节点有俩个信息x和t,分别表示这个节点上的饼干个数和先手吃掉这个节点上一个饼干的的时间.然后有先手和后手俩个人. ?先手可以这么操作:在规定总时间T到达某个节点然后一定要返回根节点1,期间可以选择吃掉某些节点上的某些饼干(前提是保证剩下的时间能够回到根节点): ?后手可以这么操作:在先手到达的位置和这个位置的孩子之间的连边选择一条让先手吃得更多的边摧毁掉,也可以跳过这个过程: 问