HDU 1723 Distribute Message DP

The contest’s message distribution is a big thing in prepare. Assuming N students stand in a row, from the row-head start transmit message, each person can transmit message to behind M personals, and how many ways could row-tail get the message?

InputInput may contain multiple test cases. Each case contains N and M in one line. (0<=M<N<=30)

When N=0 and M=0, terminates the input and this test case is not to be processed.

OutputOutput the ways of the Nth student get message.

Sample Input

4 1
4 2
0 0

Sample Output

1
3

Hint

4 1 : A->B->C->D
4 2 : A->B->C->D, A->C->D, A->B->D

OJ-ID: HDU-1723

author:Caution_X

date of submission:20190930

tags:DP

description modelling:给定N,M,表示有1~N个人排成一列,前一个人可以向后M个人传递消息,问第N个人有多少种方式接收第一个人传出的消息

major steps to solve it:dp[i]:=第i个人接收消息的方式有几种if(i-1<=M) dp[i]++;dp[i+j]+=dp[i]; j∈{1,2,3......M}.

AC CODE:

#include<stdio.h>
#include<string.h>

int dp[31],M,N;

int main()
{
    //freopen("input.txt","r",stdin);
    while(scanf("%d%d",&N,&M)!=EOF&&(N!=0||M!=0)){
        int i,j;
        memset(dp,0,sizeof(dp));
        dp[1]=1;
        for(i=2;i<=N;i++){
            if(i-1<=M){
                dp[i]++;
            }
            for(j=1;j<=M&&i+j<=N;j++){
                dp[i+j]+=dp[i];
            }
        }
        printf("%d\n",dp[N]);
    }
    return 0;
}



原文地址:https://www.cnblogs.com/cautx/p/11612443.html

时间: 2024-10-09 02:42:26

HDU 1723 Distribute Message DP的相关文章

hdu 1723 Distribute Message 递推

#include <cstdio> #include <cstring> using namespace std; int dp[50]; int main() { int n,m; while(1) { scanf("%d%d",&n,&m); if(n==0&&m==0) break; int i,j; memset(dp,0,sizeof(dp)); dp[1]=1; for(i=2;i<=n;i++) for(j=i

DP HDU 1723

简单的DP Distribute Message Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1345    Accepted Submission(s): 625 Problem Description The contest's message distribution is a big thing in prepare. As

HDU 4960 (水dp)

Another OCD Patient Problem Description Xiaoji is an OCD (obsessive-compulsive disorder) patient. This morning, his children played with plasticene. They broke the plasticene into N pieces, and put them in a line. Each piece has a volume Vi. Since Xi

HDU 1087 &amp;&amp; POJ 2533(DP,最长上升子序列).

~~~~ 两道题的意思差不多,HDU上是求最长上升子序列的和,而POJ上就的是其长度. 貌似还有用二分写的nlogn的算法,不过这俩题n^2就可以过嘛.. ~~~~ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 http://poj.org/problem?id=2533 ~~~~ HDU1087: #include<cstdio> #include<cstring> #include<algorithm> #

hdu 2296 aC自动机+dp(得到价值最大的字符串)

Ring Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3180    Accepted Submission(s): 1033 Problem Description For the hope of a forever love, Steven is planning to send a ring to Jane with a rom

hdu 2457 AC自动机+dp

DNA repair Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2004    Accepted Submission(s): 1085 Problem Description Biologists finally invent techniques of repairing DNA that contains segments c

[ACM] hdu 3555 Bomb (数位DP,统计1-N中含有“49”的总数)

Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 7187 Accepted Submission(s): 2512 Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorists impro

HDU 4833 Best Financing DP

Best Financing Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 120    Accepted Submission(s): 24 Problem Description 小 A想通过合理投资银行理财产品达到收益最大化.已知小A在未来一段时间中的收入情况,描述为两个长度为n的整数数组dates和earnings,表示在

hdu 1011(树形dp)

Mark.看着吴神博客写的,还未完全懂. 1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <algorithm> 5 #include <vector> 6 #include <queue> 7 #include <set> 8 #include <map> 9 #include <string>