HDU1723 Distribute Message(dp)

来源:互联网 发布:怎么购买高达模型 知乎 编辑:程序博客网 时间:2024/05/18 08:49

题目;

Distribute Message

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2056    Accepted Submission(s): 1026


Problem Description
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?
 

Input
Input 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. 
 

Output
Output the ways of the Nth student get message.
 

Sample Input
4 14 20 0
 

Sample Output
13
Hint
4 1 : A->B->C->D4 2 : A->B->C->D, A->C->D, A->B->D
 

Author
威士忌
 

Source
HZIEE 2007 Programming Contest
 

Recommend
lcy   |   We have carefully selected several similar problems for you:  1160 1414 1727 1725 1726 
 

Statistic | Submit | Discuss | Note
思路:

因为要传给后面的m个人,所以后面的每个人加上当前的这种情况,所以递推公式为:

dp[i+j]=dp[i+j]+dp[i]


代码:

#include <cstdio>#include <cstring>#include <cctype>#include <string>#include <set>#include <iostream>#include <stack>#include <map>#include <cmath>#include <queue>#include <vector>#include <algorithm>#define mem(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3f#define mod 1000007#define N 8#define M 12357#define ll long longusing namespace std;int n,m;int dp[35];int solve(int n,int m){memset(dp,0,sizeof(dp));dp[1] = 1;for(int i = 1; i < n; i++)for(int j = 1; j <= m; j++)dp[i+j] += dp[i];return dp[n];}int main(){while(scanf("%d%d",&n,&m)&&(n||m)){printf("%d\n",solve(n,m));}return 0;}


原创粉丝点击