UVA 12446 How Many... in 3D! ( 递推 + 树状数组 )
C. How Many... in 3D!
64-bit integer IO format: %lld Java class name: Main
Problem C: How Many... in 3D!
Given a 2x2xN box, in how many ways can you fill it with 1x1x2 blocks?

Input Format
The input starts with an integer T - the number of test cases (T <= 10,000). T cases follow on each subsequent line, each of them containing the integer N (1 <= N <= 1,000,000).
Output Format
For each test case, print the number of ways to fill the box modulo 1,000,000,007
Sample Input
3
1
2
3
Sample Output
2
9
32 今日组队赛卡住条水题,卡左成个下昼,我都唔知自己做紧咩。其他做得的题队友过晒。最后都AC左比较安慰。
写树状数组然后又唔记得update答案,好心酸。 讲下条题先,就是要用一个 1 x 1 x 2 的小立方体去填充一个 2 x 2 x N 的大立方体,有多少种方案 。 条公式就是 f( n ) = 2 * f ( n -1 ) + 5*f( n -2 ) + 4 * sigma f( n - 3 );
f(n)就表示叠满到第n层的数量
首先 f(n - 1) 层到 f(n)就只有两种方案而已 。
然后 f(n - 2) 层到 f(n)有5种 , 全部竖着放 1 种 , 两个横两个竖 4 种 。
而 4 * sigma f( n-3 )就是 f( k ) [ 0<= k <= n-3 ] 意思就是 到达 k 层是刚好覆盖了的 ,
然后 k ~ n 层是 竖着放 参差 不齐的
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
const int N = ;
const int mod = ;
LL c[N];
LL ans[N]; int lowbit(int x){return x&-x;}
void update(int pos,int key){
while( pos<=1e6 ){
c[pos] += key;
c[pos] %= mod;
pos += lowbit(pos);
}
} LL query(int pos ){
LL res=;
while(pos>){
res += c[pos];
res %= mod;
pos -= lowbit(pos);
}
return res;
}
void init()
{
update(,);
update(,); ans[] = ;
ans[] = ; for(int i= ; i <=N- ;++i){
LL res = ( *query( i- ) )%mod;
res = (res + *ans[i-]) % mod;
res = (res + *ans[i-]) % mod;
ans[i] = res;
update(i,ans[i]);
} }
int main()
{
int _,n;
init();
scanf("%d",&_);
while(_--){
scanf("%d",&n);
printf("%lld\n",ans[n+]);
}
return ;
}
UVA 12446 How Many... in 3D! ( 递推 + 树状数组 )的更多相关文章
- ACM学习历程—UESTC 1217 The Battle of Chibi(递推 && 树状数组)(2015CCPC C)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 题目大意就是求一个序列里面长度为m的递增子序列的个数. 首先可以列出一个递推式p(len, i) = ...
- HDU 4455 Substrings --递推+树状数组优化
题意: 给一串数字,给q个查询,每次查询长度为w的所有子串中不同的数字个数之和为多少. 解法:先预处理出D[i]为: 每个值的左边和它相等的值的位置和它的位置的距离,如果左边没有与他相同的,设为n+8 ...
- Code Chef JUMP(递推+树状数组+李超线段树)
\(JUMP\) 很容易写出转移柿子 \[f_i=\min_{p_j<p_i}\{(h_i-h_j)^2+f_j\}+w_i\] 把\(\min\)里面的东西展开一下 \[f_j=\min_{p ...
- HDOJ 4455 Substrings 递推+树状数组
pre[i]第i位数往前走多少位碰到和它同样的数 dp[i]表示长度为i的子串,dp[i]能够由dp[i-1]加上从i到n的pre[i]>i-1的数减去最后一段长度为i-1的断中的不同的数得到. ...
- Hdu4742-Pinball Game 3D(cdq分治+树状数组)
Problem Description RD is a smart boy and excel in pinball game. However, playing common 2D pinball ...
- hdu_4742_Pinball Game 3D(cdq分治+树状数组)
题目链接:hdu_4742_Pinball Game 3D 题意: 给你n个点,让你求三维的LIS,并且求出有多少种组合能达到LIS. 题解: 求三维的LIS,典型的三维偏序问题,x排序,解决一维,c ...
- HDU 4247 Pinball Game 3D(cdq 分治+树状数组+动态规划)
Pinball Game 3D Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- UVa 11384 - Help is needed for Dexter 分析, 树状数组 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVA - 590Always on the run(递推)
题目:UVA - 590Always on the run(递推) 题目大意:有一个小偷如今在计划着逃跑的路线,可是又想省机票费. 他刚開始在城市1,必须K天都在这N个城市里跑来跑去.最后一天达到城市 ...
随机推荐
- Python之获取文件夹中文件列表以及glob与fnmatch模块的使用
获取文件夹中的文件列表 print(os.listdir("../secondPackage")) # ['__init__.py', 'secondCookBook.py', ' ...
- JS高级 — 函数中的this指向问题
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- 纯css实现星级评分效果
效果 效果图如下,纯css实现超酷炫的星级评分动画效果 实现思路 5个类型为radio的input,label标签修改样式背景图为星星 label标签给每个星星鼠标停留时加注名字 点击星星有放大旋 ...
- vue项目一个页面使用多个轮播图详解
1.html代码: <div v-for="(item,index) in arrDataList.Floor"> // 根据后台数据循环渲染多个轮播图组件 <d ...
- [数论]原根与指标,BSGS
刚学了这方面的知识,总结一下.推荐学习数论方面的知识还是看书学习,蒟蒻看的是<初等数论>学的. 这里也推荐几个总结性质的博客,学习大佬的代码和习题. 原根:https://blog.csd ...
- CS184.1X 计算机图形学导论 HomeWork1
最容易填写的函数就是left.输入为旋转的角度,当前的eye与up这两个三维向量 void Transform::left(float degrees, vec3& eye, vec3& ...
- Vue:列表渲染 v-for on a <template>
类似于 v-if,你也可以利用带有 v-for 的 <template> 渲染多个元素.比如: <html> <head> <title>Vue v-f ...
- java下载文件demo
java通过http方式下载文件 https://www.cnblogs.com/tiancai/p/7942201.html
- 关于嵌入式linux下的串口通讯问题---需增加回车/换行才能接收
问题:在Linux应用层,直接从/dev/tty***使用read()函数读数据,无法读到,只有在数据末尾加上0a/0d才可以读到数据(这里是发送十六进制的数据,ASCLL码同理,增加回车才可以读到数 ...
- websock(AMQ)通信-前端
服务端和客户端之间的通信 前端开发经常会依赖后端,那么如果后端服务器还没做好推送服务器,那么前端该如何呢.最简单的就是自己模拟一个服务器,用node来搭建,这边只简单介绍搭建的过程 node搭建服务器 ...