求助大佬,帮我看看我的代码有啥问题,指点一下!
查看原帖
求助大佬,帮我看看我的代码有啥问题,指点一下!
528548
tank__Battleship楼主2023/3/31 21:53

取物品问题

题目描述

问题描述:

有n(n<=10)个不同的物品,要求取其中m个(0<=m<=n),请问有几种取法?

输入格式:

一行,两个数: n m

输出格式:

一行一个数字输出方案数

输入 4 2

输出样例1:

6

我的代码

#include<bits/stdc++.h>
using namespace std;
int f[1005][1005];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	f[0][0]=1;
	for(int i=1;i<=n;i++){
		f[i][0]=0;
		for(int j=1;j<=i;j++)f[i][j]=f[i-1][j]+f[i-1][j-1];
	}
	printf("%d\n",f[n][m]);
	return 0;
}
2023/3/31 21:53
加载中...