codeforces 414B B. Mashmokh and ACM(dp)

题目链接:

codeforces 414B


题目大意:

定义一个序列,前一项能够整除后一项,给定这个序列中数的取值范围和序列的长度,问有多少种构造方法。


题目分析:

  • 我们定义状态dp[i][j]为前i项已经确定且第i项为j的方案数。
  • 转移方程

    dp[i][j]=∑k|jdp[i?1][k]
  • 复杂度O(n?k)

AC代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#define MAX 2007

using namespace std;

typedef long long LL;

int n,k;
const LL mod=1e9+7;
LL dp[MAX][MAX];

int main ( )
{
    while ( ~scanf ( "%d%d" , &n , &k ) )
    {
        memset ( dp , 0 , sizeof ( dp ) );
        for ( int i = 1 ; i <= n ; i++ )
            dp[1][i] = 1;
        for ( int i = 2 ; i <= k ; i++ )
            for ( int j = 1 ; j <= n ; j++ )
                for ( int k = 1 ; k*k<=j ; k++ )
                {
                    if ( j%k ) continue;
                    dp[i][j] += dp[i-1][k];
                    dp[i][j] %= mod;
                    int x = j/k;
                    if ( x == k ) continue;
                    dp[i][j] += dp[i-1][x];
                    dp[i][j] %= mod;
                }
        int ans = 0;
        for ( int i = 1 ; i <= n ; i++ )
        {
            ans += dp[k][i];
            ans %= mod;
        }
        printf ( "%d\n" , ans );
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-05 11:18:48

codeforces 414B B. Mashmokh and ACM(dp)的相关文章

【codeforces 415D】Mashmokh and ACM(普通dp)

[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=2000),问满足[数列长度是k && 数列中每一个元素arr[i]在1~n之间 && 数列中元素可以重复]的数列有多少个?结果对10^9+7取余 解题思路:dp[i][j]表示长度是j,最后一位是i的种数 if(kk%i==0) dp[kk][j+1]+=dp[i][j] 1 #i

Codeforces 414B 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 #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

cf 414B Mashmokh and ACM 动态规划

题目链接:http://codeforces.com/problemset/problem/414/B dp[i][j]表示长度为i.最后一个数字为j的合法序列总数 dp[1][1...2000]都是1 后面用dp[i-1][j] 去更新 dp[i][j*t] (1 <= j*t <= 2000) 即用因子去更新它的倍数 表面上看是2000^3的复杂度会爆 其实不用算那么多次 最外层循环是2000 分析第二层和第三层 需要算 2000/1 + 2000/2 + 2000/3 + 2000/4

CodeForces 540D Bad Luck Island 概率dp

CodeForces 540D 应该是简单概率dp,由于写得少显得十分蠢萌 求期望逆推,求概率正推,大概是这么个意思,贴一发留恋 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define db double const int maxn=108; db dp[maxn][maxn][maxn]; int main() { int i,j,n,m,k,p; whi

codeforces 148E Aragorn&#39;s Story 背包DP

Aragorn's Story Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/148/E Description Our protagonist is the handsome human prince Aragorn comes from The Lord of the Rings. One day Aragorn finds a lot of enemies who

CodeForces 21D Traveling Graph 状压dp+欧拉回路

题目链接:点击打开链接 题意: 给定n个点m条边的无向图 求从1点开始经过每条边至少一次最后回到1点的最小路程 显然就是找一条路径可重复的欧拉回路 思路: 首先对于欧拉回路的结论是:所有点的度数都为偶数 因为所有边至少经过一次,那么可以把题意转换成加最少多少条边使得图满足以上结论 而加的边目的是为了把奇度数转成偶度数,先floyd一下得到任意点间加边的最小花费 dp[i]表示状态i下度数都为偶数的最小花费. 状压dp,把i状态下,所有未选择的点中挑2个奇度数的转移即可. #include <cs

Codeforces 67C Sequence of Balls 编辑距离 dp

题目链接:点击打开链接 有一个交换操作比较特殊,所以记录每个点距离自己最近的那个字符的位置 然后交换就相当于把第一行要交换的2个字符 之间的字符都删掉 把第二行要交换的2个字符 之间的字符都插入第一行的2个字符之间 然后再进行交换. #include <cstdio> #include <cstring> #include<iostream> using namespace std; #define inf 10000000 #define N 4005 #define

Codeforces Round #261 (Div. 2) E (DP)

E. Pashmak and Graph Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he can't solve this problem. As you know, he's really weak at graph theory; so try to help him in solving the problem. You are