B. Mashmokh and ACM
来源:互联网 发布:vb.net实例教程 编辑:程序博客网 时间:2024/05/22 02:31
题目链接:http://codeforces.com/problemset/problem/414/B
题意:就是给你一个n和k,让你用1 -- n这n个数,选出k个组成一个序列,这个序列满足任意后面一个都能够整除前面一个。求这个序列的个数、
分析:比赛的时候以为是数论的题目,直接分给搞数论的队友了,他说没有思路,我趁着电脑闲的打了一下表看看能不能发现点规律,但是没有,其实这道题目完全可以解决的。
记忆话深搜或者dp
由于其后面一个数是多少直接由他前面的数来决定,那么我们可以定义一个跟末尾数字有关的状态,dp[ i ] [ j ] 表示长度为 i 的序列最后一位是 j ,那么
状态转移方程:dp 【i】【j】 = sum(dp【i-1】【x】) x是j前面满足(j%x==0)的数。那么代码就很好写了。
可以直接打表缩短时间,但是cf是单组数据判题,下来时间反而长了。。。
感觉做题策略还是有问题,队长不称职!
代码:
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;const int MOD=1000000007;const int N = 2002;int dp[2005][2005];int isit(){ for(int i=1; i<=2002; i++) dp[1][i]=1; for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { for (int z = j; z <= N; z+=j) { dp[i][z] = (dp[i][z]+dp[i-1][j])%MOD; } } }}int main(){ int n,k; isit(); while(cin>>n>>k) { int ans = 0; for (int i = 1; i <= n; i++) { ans+=dp[k][i]; ans%=MOD; } cout<<ans<<endl; } return 0;}
0 0
- B. Mashmokh and ACM
- B. Mashmokh and ACM
- CF B. Mashmokh and ACM dp
- CodeForces 414B--Mashmokh and ACM (dp)
- Mashmokh and ACM - CodeForces 414B dp
- Codeforce--414B--Mashmokh and ACM
- codeforces 414B Mashmokh and ACM
- codeforces--414B--Mashmokh and ACM
- codeforces-414B-Mashmokh and ACM
- CF 414B Mashmokh and ACM
- Codeforces 414b Mashmokh and ACM
- codeforces 414B B. Mashmokh and ACM(dp)
- Mashmokh and ACM
- 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 Round #240 (Div. 1)---B.Mashmokh and ACM(dp)
- VS2010 solution中完美的相对路径引用方法
- cocos2dx3.0rc如何创建新工程
- 第七周作业
- Twitter 宣布收购社交数据提供商 Gnip
- 我的简历
- B. Mashmokh and ACM
- 《Java解惑》系列——01表达式之谜——谜题07:互换内容
- UIView转场动画 IOS
- nginx限制ip访问权限
- 深入研究用户提升关键词排名
- arm上安装openssh
- Mysql中的char与varchar length()与char_length()
- PHP SPL笔记
- Linux禁止用户登录