B. Mashmokh and ACM(dp)
http://codeforces.com/problemset/problem/414/B
1 second
256 megabytes
standard input
standard output
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).
The first line of input contains two space-separated integers n, k (1 ≤ n, k ≤ 2000).
Output a single integer — the number of good sequences of length k modulo 1000000007 (109 + 7).
- 3 2
- 5
- 6 4
- 39
- 2 1
- 2
In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3].
题意:1~n组成的不下降序列,求出序列长度为k的序列种数,每个序列满足序列中的后一个数都能整除前一个数。
思路:后一个数的确定只与前一个数有关,设dp[i][j]表示长度为i的序列中的最后一个数为j,则dp[i][z] = dp[i][z]+dp[i-1][j],其中z是j的倍数。
- #include <stdio.h>
- #include <string.h>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- const int MOD=;
- int dp[][];
- int main()
- {
- int n,k;
- while(cin>>n>>k)
- {
- memset(dp,,sizeof(dp));
- for (int i = ; i <= n; i++)
- dp[][i] = ;
- for (int i = ; i <= k; i++)
- {
- for (int j = ; j <= n; j++)
- {
- for (int z = j; z <= n; z+=j)
- {
- dp[i][z] = (dp[i][z]+dp[i-][j])%MOD;
- }
- }
- }
- int ans = ;
- for (int i = ; i <= n; i++)
- {
- ans+=dp[k][i];
- ans%=MOD;
- }
- cout<<ans<<endl;
- }
- return ;
- }
B. Mashmokh and ACM(dp)的更多相关文章
- codeforces 414B B. Mashmokh and ACM(dp)
题目链接: B. Mashmokh and ACM time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Codeforces Round #240 (Div. 1) B. Mashmokh and ACM DP
B. Mashmokh and ACM ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- codeforces D.Mashmokh and ACM
题意:给你n和k,然后找出b1, b2, ..., bl(1 ≤ b1 ≤ b2 ≤ ... ≤ bl ≤ n),并且对所有的bi+1%bi==0,问有多少这样的序列? 思路:dp[i][j] 表示长 ...
- CodeForces 415D Mashmokh and ACM
$dp$. 记$dp[i][j]$表示已经放了$i$个数字,并且第$i$个数字放了$j$的方案数.那么$dp[i][j] = \sum\limits_{k|j}^{} {dp[i - 1][k]}$ ...
- CF414B Mashmokh and ACM
思路: dp. 实现: 1.O(n5/2) #include <iostream> #include <cstdio> using namespace std; ; ][]; ...
- CF 414B Mashmokh and ACM 动态规划
题意: 给你两个数n和k.求满足以下条件的数列有多少个. 这个数列的长度是k: b[1], b[2], ……, b[k]. 并且 b[1] <= b[2] <= …… <= b[k] ...
- Codeforces 414B Mashmokh and ACM
http://codeforces.com/problemset/problem/414/B 题目大意: 题意:一个序列B1,B2...Bl如果是好的,必须满足Bi | Bi + 1(a | b 代表 ...
- Mashmokh and ACM CodeForces - 414D (贪心)
大意: 给定n结点树, 有k桶水, p块钱, 初始可以任选不超过k个点(不能选根结点), 在每个点放一桶水, 然后开始游戏. 游戏每一轮开始时, 可以任选若干个节点关闭, 花费为关闭结点储存水的数量和 ...
随机推荐
- UVA - 1619 Feel Good(扫描法)
题目: 思路: 预处理出a[i]在哪个范围区间内是最小的,然后直接遍历a数组求答案就可以了. 这个预处理的技巧巧妙的用了之前的处理结果.(大佬tql) 代码: #include <bits/st ...
- CentOS \Linux文件权限详解
文件和目录权限概述 在linux中的每一个文件或目录都包含有访问权限,这些访问权限决定了谁能访问和如何访问这些文件和目录. 通过设定权限可以从以下三种访问方式限制访问权限:只允许用户自己访问:允许一个 ...
- Xshell(smarTTY)连接Linux虚拟机失败(未开放22端口)解决办法
1.关闭防火墙: 命令:sudo ufw disable 2.安装openssh-server以及openssh-client: 命令:sudo apt-get install openssh-ser ...
- Django DTL模板语法中的url反转
"""template_url_demo URL Configuration The `urlpatterns` list routes URLs to views. F ...
- MySQL 查询状态
查询状态 SHOW FULL PROCESSLIST 对于一个连接,或者说一个线程,任何时刻都有一个状态,该状态表示了MySQL当前正在做什么. mysql>SHOW FULL PROCESSL ...
- maven profile多环境自动切换配置,配置分离,排除文件
痛点: 在java开发的过程中,我们经常要面对各种各样的环境,比如开发环境,测试环境,正式环境,而这些环境对项目的需求也不相同. 在此之前,我们往往需要手动去修改相对应的配置文件然后打成war,才能部 ...
- How Can You Tell the Difference Between LINQ Methods and Query Builder Methods?
LINQ's method syntax looks very similar to the query builder methods,except for one big difference:t ...
- 【Codeforces 986B】Petr and Permutations
[链接] 我是链接,点我呀:) [题意] 题意 [题解] n为奇数时3n和7n+1奇偶性不同 n为偶数时也是如此 然后交换任意一对数 逆序对的对数的奇偶性会发生改变一次 求出逆序对 对n讨论得出答案. ...
- bzoj 1664 (贪心)
[Usaco2006 Open]County Fair Events 参加节日庆祝 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 487 Solved: ...
- 文化之旅 2012年NOIP全国联赛普及组
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 有一位使者要游历各国,他每到一个国家,都能学到一种文化,但他不愿意学习任何一种文化超 ...