zoukankan      html  css  js  c++  java
  • Codeforces Round #240 (Div. 2) D


    D. Mashmokh and ACM

    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

     题意:给出一组数列,问满足数列递增且前一个元素能整除后一个元素的数列一共有多少种。

     sl:赤裸裸的dp,比赛时叫C整的快没时间了,十分钟敲了下交了一发wa了原来忘记mod1e9了。

    dp方程:  dp[i][j]+=dp[i-1][k]  (j%k==0) 只要预处理因子就可以了。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #include<vector>
     5 using namespace std;
     6 const int MAX = 2000+10;
     7 const int MOD = 1e9+7;
     8 int dp[MAX][MAX];
     9 vector<int> v[MAX];
    10 void init()
    11 {
    12     memset(dp,0,sizeof(dp));
    13     for(int i=1;i<MAX;i++) dp[1][i]=1;
    14     for(int i=1;i<MAX;i++)
    15     {
    16         for(int j=1;j<=i;j++)
    17         {
    18             if(i%j==0) v[i].push_back(j);
    19         }
    20     }
    21 }
    22 int main()
    23 {
    24     int n,k;
    25     init();
    26     scanf("%d %d",&n,&k);
    27     for(int j=1;j<=n;j++)
    28     for(int i=2;i<=k;i++)
    29     {
    30         for(int m=0;m<v[j].size();m++)
    31         {
    32             dp[i][j]=(dp[i][j]+dp[i-1][v[j][m]])%MOD;
    33         }
    34     }
    35     int ans=0;
    36     for(int i=1;i<=n;i++) ans=(ans+dp[k][i])%MOD;
    37     printf("%d ",ans%MOD);
    38     return 0;

    39 } 

  • 相关阅读:
    laravel 单元测试 phpunit 运行报错 RuntimeException: No application encryption key has been specified 解决
    pace.js 自动加载进度条插件的简单使用教程
    git push 报错 ERROR: Permission to xxx.git denied to someuser
    Laravel 框架对于分表进行统计合并查询的思路
    解决tail命令提示“tail: inotify 资源耗尽,无法使用 inotify 机制,回归为 polling 机制”
    phpredis 报错 “Function Redis::setTimeout() is deprecated” 解决方法
    laravel 5.5.39 升级到 5.5.45 出现 cookie 序列化异常问题的解决
    vue.js 实战 todo list
    BootstrapVue 安装指南
    05js语法检查、js兼容性处理
  • 原文地址:https://www.cnblogs.com/acvc/p/3649935.html
Copyright © 2011-2022 走看看