P2028 Longxiong picking apples

Title Description

Tao Tao Xiong in the orchard picking apples are picked in a completely different from each other n Apple, hospitable park owner provided him with the k basket, he wanted to apples in baskets carry home (Because of Longxiong hands is infinite, so you do not have to consider that he can simultaneously carry so many baskets). At the same time, he does not want any one basket is empty, because it could not do the best use = =. So he wanted to know how many ways to put a total of apples, due to his brain operation is too slow, so you find a clever wit, he has spent picking apples in a long time, so he can only wait one second. (Method likely to be very very very very very very very very very very very very very very very very very very very very very very much, Xiong brain can not be stored, so he will give you the number of a number p, p divided by the output method the remainder on it)

Input Format

Three line number, followed by n, k, p, such as the title meaning face shown.

Output Format

A number is divided by the number of ways p, the end of the line there is a carriage return.

Sample input and output

Input # 1
4 2 3
Output # 1
1

Description / Tips

[H1 of] Sample explained [/ h1]

A total of four apples, two baskets.

There are 7 ways

{1}{2,3,4};{2}{1,3,4};{3}{1,2,4};{4}{1,2,3};

{1,2}{3,4};{1,3}{2,4};{1,4}{2,3}。

7 divided by more than 31.

Data range [h1] [/ h1]

20% of the data, n <= 8, k <= 8.

60% of the data, n <= 100, k <= 100.

100% data, n <= 10000, k <= 1000.

To ensure that all data n> = k, and the answer in the range of 64-bit integer.

 

 

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
unsigned long long f[10001][1001];
int main(){
    long long n,m,mo;
    scanf("%lld%lld%lld",&n,&m,&mo);
    f[1][1]=f[1][1]|1;
    for (int i=1;i<=n;i++){
        f[i][1]=f[1][1]|1;
        for (int j=1;j<=m;j++){
            if(i==1&&j==1){continue;}
            f[i][j]=((j%mo)*(f[i-1][j]%mo)%mo+(f[i-1][j-1])%mo)%mo;
        }
    }
    printf("%llu",f[n][m]);
}

  

Guess you like

Origin www.cnblogs.com/xiongchongwen/p/11261589.html