Codeforces 414B B. Mashmokh and ACM (DP)

Source: Internet
Author: User

Topic Links:

Codeforces 414B

Main topic:

Defines a sequence in which the previous item is divisible to the next, given the range of values in the sequence and the length of the sequence, and how many constructs are asked.

Topic Analysis:
  • We define the state Dp[i][j] as the number of scenarios in which the previous I term has been determined and item I is J.
  • Transfer equation d P[I][J]= ∑ k| J d P[I?1][k]
  • Complexity of O ( n k )
AC Code:
#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>#define MAXusing namespace STD;typedef Long LongLL;intN,k;ConstLL mod=1e9+7; LL Dp[max][max];intMain () { while( ~scanf("%d%d", &n, &k)) {memset(DP,0,sizeof(DP)); for(inti =1; I <= N; i++) dp[1][i] =1; for(inti =2; I <= K; i++) for(intj =1; J <= N; J + +) for(intK =1; K*k<=j; k++) {if(j%k)Continue; DP[I][J] + = dp[i-1][K]; DP[I][J]%= mod;intx = j/k;if(x = = k)Continue; DP[I][J] + = dp[i-1][X];                DP[I][J]%= mod; }intAns =0; for(inti =1; I <= N;            i++) {ans + = dp[k][i];        Ans%= MoD; }printf("%d\n", ans); }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces 414B B. Mashmokh and ACM (DP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.