码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 1723 Distribute Message DP

时间:2019-09-30 14:58:16      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:ane   个人   could   lin   test   sum   print   memset   rip   

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;
}
View Code

 





HDU 1723 Distribute Message DP

标签:ane   个人   could   lin   test   sum   print   memset   rip   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!