洛谷 P1754 球迷购票问题(DP/Catalan)
https://www.luogu.com.cn/problem/P1754
题目大意:
一共有2*n个人,n个人拿着50元的,n个人拿着100元的,但是卖票处一开始没有钱可以找。
问我们这些人怎样排列才可以完美的实现销售流程。
输入 #1
2
输出 #1
2
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=1e5+10,M=4023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
LL n,f[M][M];
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T=1;
//cin>>T;
while(T--)
{
cin>>n;
f[0][0]=0;
for(int i=1;i<=n;i++)
{
f[i][0]=1;//有50元的首先放一张在前面,只有一种情况
f[0][i]=0;//有100元的必须放在有50的后面,没50的则没有结果
}
for(int i=1;i<=n;i++)//放了i张50的
{
for(int j=1;j<=i;j++)//放了j张100的
{
//这里可以放的数量就==直接放的50的数量加直接放的100的数量
f[i][j]=f[i-1][j]+f[i][j-1];
}
}
/*
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
cout<<f[i][j]<<" ";
}
cout<<endl;
}
*/
cout<<f[n][n]<<endl;
}
return 0;
}