Loaded plate

Time: 1000ms Memory Limit: 10000K Total time: 3000ms

description:

N people to appetite, food line to the cloud floor, take the N plate, playing M dumplings. Now wishing M of N dumplings into the dish, ask how many different installation method?
Assuming that the plate is large enough, and the dish can not put anything. Note that the image belongs to the same discharge method 250, and 502 and the like.

Input:

Two integers M, N (1 = <M, N <= 100) separated by a space.

Output:

There are several separate output line installation method.

Sample input:

7 3

Sample output:

8

#include <iostream>
using namespace std;

int put(int m, int n)
{
    if( m == 0 || m == 1 || n == 1 )
    {
        return 1;
    }
    int dp[n+1][m+1];
    for( int i = 0; i <= n; i++ )
    {
        for( int j = 0; j <= m; j++ )
        {
            dp[i][j] = 1;
        }
    }

    for( int i = 2; i <= n; ++i)
    {
        for( int j = 2; j <= m; ++j)
        {
            if( i > j )
            {
                dp[i][j] = dp[j][j];
            }
            else
            {
                dp[i][j] = dp[i - 1][j] + dp[i][j - i];
            }
        }
    }
    return dp[n][m];
}
int main()
{
	int m,n;
	cin >> m >> n;
	cout << put(m,n) << endl;
	return 0;
}

 

Published 105 original articles · won praise 53 · views 60000 +

Guess you like

Origin blog.csdn.net/zhao2018/article/details/83420961