HDU 1723 Distribute Message DP
Posted cautx
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 0Sample Output
1 3Hint
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 ",dp[N]); } return 0; }
以上是关于HDU 1723 Distribute Message DP的主要内容,如果未能解决你的问题,请参考以下文章
加法和XOR的搞搞--二进制(HDU4149 Magic Potion)
error writing messa ge: File too large
英语单词distribute和dispatch意义上有啥区别?