洛谷 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;
}
本文作者:Vivian-0918
本文链接:https://www.cnblogs.com/Vivian-0918/p/17269907.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
分类:
dp
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步