poj 2506 Tiling(大数+递推)
2016-07-27 10:17
330 查看
递推公式 s[i] = s[i-2]*2 + s[i-1]
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int s[255][100];
void fun()
{
s[0][0] = 1;//一定要加上,否则wa
s[1][0] = 1;
s[2][0] = 3;
int temp = 0, i, j;
for(i = 3;i <= 250;i++){
for(j = 0;j < 100;j++){
temp += (s[i-2][j])*2 + s[i-1][j];
s[i][j] = temp%10;
temp /=10;
}
}
}
int main()
{
fun();
int n;
int i;
while(cin >> n){
for(i = 99;i >= 0;i--){
if(s
[i] != 0)
break;
}
for(;i>=0;i--){
cout << s
[i];
}
cout << endl;
}
return 0;
}
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int s[255][100];
void fun()
{
s[0][0] = 1;//一定要加上,否则wa
s[1][0] = 1;
s[2][0] = 3;
int temp = 0, i, j;
for(i = 3;i <= 250;i++){
for(j = 0;j < 100;j++){
temp += (s[i-2][j])*2 + s[i-1][j];
s[i][j] = temp%10;
temp /=10;
}
}
}
int main()
{
fun();
int n;
int i;
while(cin >> n){
for(i = 99;i >= 0;i--){
if(s
[i] != 0)
break;
}
for(;i>=0;i--){
cout << s
[i];
}
cout << endl;
}
return 0;
}
相关文章推荐
- iOS之UITabBar的简单使用
- TextView 你真的懂我么
- HTML初涉(4)
- intellijidal如何将一个普通的java项目转变成maven项目
- Redis 命令
- 分类器
- 顺序表应用1:多余元素删除之移位算法 7.16补
- POJ-2752 Seek the Name, Seek the Fame(kmp中next数组的应用)
- <item> tag requires a 'drawable' attribute"-selector设置颜色不成功-解决方案
- linux磁盘挂载
- 盒子模型
- MySQl workbench ER转SQL
- LinQ to SQL用法详解
- web--iPhone适配
- SIP DB33标准笔记 监控图像获取
- 求n的阶乘(10000)
- Redis 数据类型
- HDU 3367
- 正确运行携程DynamicAPK
- 四.swift - string