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

Author

威士忌

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <limits.h>
#include <ctype.h>
#include <string.h>
#include <string>
#include <math.h>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <deque>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define MAXN 35
int dp[MAXN];

int main(){
    int n,m;
    int i,j;

    while(~scanf("%d%d",&n,&m)){
        if(n==0 && m==0){
            break;
        }
        memset(dp,0,sizeof(dp));
        dp[1] = 1;
        for(i=1;i<=n;i++){
            for(j=1;j<=m;j++){
                if((i+j)<=n){
                    dp[i+j] = dp[i+j]+dp[i];
                }
            }
        }
        printf("%d\n",dp[n]);
    }

    return 0;
}
时间: 2024-08-11 05:30:42

DP HDU 1723的相关文章

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 数塔(水题)

数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 21314    Accepted Submission(s): 12808 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少

fwt优化+树形DP HDU 5909

1 //fwt优化+树形DP HDU 5909 2 //见官方题解 3 // BestCoder Round #88 http://bestcoder.hdu.edu.cn/ 4 5 #include <bits/stdc++.h> 6 // #include <iostream> 7 // #include <cstdio> 8 // #include <cstdlib> 9 // #include <algorithm> 10 // #inc

I DP Hdu 1421

<span style="color:#3333ff;">/* ______________________________________________________________________________________________________ author : Grant Yuan time : 2014.7.19 algorithm : dp explain : 首先对所有的物体按照重量的从小到大进行一次排序,第i件物体只能和第i-1件物体配对;

dp --- hdu 4939 : Stupid Tower Defense

Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1219    Accepted Submission(s): 361 Problem Description FSF is addicted to a stupid tower defense game. The goal of tower

[数位dp] hdu 3967 Zero&#39;s Numberd

题意:对于两个数i和k,把它分为两个部分的数,n和m,如果(n+m)%k=0 那么这算一种分法 比如 333可分成,3.33或者33.3,对于 (333,3)就等于2. 现在给出 a.b.k,为 (a~b,k)有多少种分法 思路:对于一个数,注意前导零并枚举分点就好了. dp[22][22][22][22][2],   代表 i位,分点为fd,余数mod,对于k取余,是否有前导零 代码: #include"cstdlib" #include"cstdio" #inc

hdu 1723 DP/递推

题意:有一队人(人数 ≥ 1),开头一个人要将消息传到末尾一个人那里,规定每次最多可以向后传n个人,问共有多少种传达方式. 这道题我刚拿到手没有想过 DP ,我觉得这样传消息其实很像 Fibonacci 所举的例子:一个人每次能够跨一或二阶台阶,问到 n 阶台阶有几种跨法.理念是一样的,只不过跨得台阶数可能会变而已.根据 Fibonacci 数列类比过来,每次最多能传 m 人,则 A [ i ] = A [ i - m ] + A [ i - m + 1 ] +  …… + A [ i - 1

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? Inpu

概率dp HDU 3853

H - LOOPS Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 3853 Appoint description:  System Crawler  (2014-10-22) Description Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl). Homura wa