Codevs 2956 排队问题
2024-08-23 15:40:39
2956 排队问题
时间限制: 1 s 空间限制: 32000 KB 题目等级 : 黄金 Gold
题目描述 Description
有N个学生去食堂,可教官规定:必须2人或3人组成一组,求有多少种不同分组的方法。
输入描述 Input Description
一个数,N
输出描述 Output Description
一个数,即答案。
样例输入 Sample Input
6
样例输出 Sample Output
2
数据范围及提示 Data Size & Hint
N<=150
50分TLE代码存档:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int n,ans;
void dfs(int x)
{
if(x==){
ans++;return ;
}
else if(x<&&x!=) return;
dfs(x-);
dfs(x-);
}
int main()
{
scanf("%d",&n);
dfs(n);
printf("%d",ans);
return ;
}
正解:
#include<cstdio>
#define ll long long
using namespace std;
ll f[];
int main() {
int n;
scanf("%d", &n);
f[]=; f[]=f[]=;
for(int i=;i<=n;i++) f[i]=f[i-]+f[i-];
printf("%lld\n", f[n]);
return ;
}
// 这题居然是递推!!!!!!
最新文章
- mysql每秒最多能插入多少条数据 ? 死磕性能压测
- Ubuntu下tftp服务搭建
- HDU 4432 Sum of divisors (进制模拟)
- Egret HTTP网络
- android的task任务栈
- centos 彻底删除nodejs默认的安装文件
- wxWidgets+wxSmith版电子词典
- .Net2.0 --Winform结合WebBrowser控件和Socket老技术来实现另类Push~
- ZOJ 1011 - NTA
- JS 函数节流和去抖
- Python 安装包的导入
- 解决无法打开myeclipse-->;“The default workspace&#39;D: /myeclipse spaceis in use or cannot be created. Please choose a different one”
- 使用nginx做反向代理和负载均衡效果图
- Ajax(Asynchronous JavaScript )and xml
- linux下主从同步和redis的用法
- python pyMysql 自定义异常 函数重载
- Sql Server 查询库表记录数
- IDEA 2017 破解
- RabbitMQ双活实践(转)
- linux命令之系统管理命令(上)
热门文章
- Docker镜像的目录存储讲解
- Educational Codeforces Round 11 C hard process_补题——作为司老大的脑残粉
- Data truncation: Data too long for column &#39;id&#39; at row 1
- Python字符编码及字符串
- snprintf()返回值的陷阱
- swift中使用sqlite3
- HTML5 Canvas奇幻色彩Loading加载动画
- css布局--两列布局,左侧固定,右侧自适应(其中左侧要可以拖动,右侧水平滚动条)
- 几种优化web页面加载速度的策略
- 王小胖之 Base64编码/解码