标签:ane 个人 could lin test sum print memset rip
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\n",dp[N]); } return 0; }
HDU 1723 Distribute Message DP
标签:ane 个人 could lin test sum print memset rip
原文地址:https://www.cnblogs.com/cautx/p/11612443.html