C. How Many... in 3D!

Time Limit: 1000ms
Memory Limit: 131072KB

64-bit integer IO format: %lld      Java class name: Main

Submit                 Status                 PID: 20864              

[PDF Link]

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! ( 递推 + 树状数组 )的更多相关文章

  1. ACM学习历程—UESTC 1217 The Battle of Chibi(递推 && 树状数组)(2015CCPC C)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 题目大意就是求一个序列里面长度为m的递增子序列的个数. 首先可以列出一个递推式p(len, i) =  ...

  2. HDU 4455 Substrings --递推+树状数组优化

    题意: 给一串数字,给q个查询,每次查询长度为w的所有子串中不同的数字个数之和为多少. 解法:先预处理出D[i]为: 每个值的左边和它相等的值的位置和它的位置的距离,如果左边没有与他相同的,设为n+8 ...

  3. 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 ...

  4. HDOJ 4455 Substrings 递推+树状数组

    pre[i]第i位数往前走多少位碰到和它同样的数 dp[i]表示长度为i的子串,dp[i]能够由dp[i-1]加上从i到n的pre[i]>i-1的数减去最后一段长度为i-1的断中的不同的数得到. ...

  5. Hdu4742-Pinball Game 3D(cdq分治+树状数组)

    Problem Description RD is a smart boy and excel in pinball game. However, playing common 2D pinball ...

  6. hdu_4742_Pinball Game 3D(cdq分治+树状数组)

    题目链接:hdu_4742_Pinball Game 3D 题意: 给你n个点,让你求三维的LIS,并且求出有多少种组合能达到LIS. 题解: 求三维的LIS,典型的三维偏序问题,x排序,解决一维,c ...

  7. HDU 4247 Pinball Game 3D(cdq 分治+树状数组+动态规划)

    Pinball Game 3D Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. UVa 11384 - Help is needed for Dexter 分析, 树状数组 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  9. UVA - 590Always on the run(递推)

    题目:UVA - 590Always on the run(递推) 题目大意:有一个小偷如今在计划着逃跑的路线,可是又想省机票费. 他刚開始在城市1,必须K天都在这N个城市里跑来跑去.最后一天达到城市 ...

随机推荐

  1. c# UDP分包发送

    考虑到UDP的高速和其他协议的复杂性,做了一个依靠时间发送的分包组包重发的UDP库. https://github.com/jinyuttt/UDPTTL.git

  2. JS中对象数据类型的基本结构和操作

    Object类型 ECMAScript中的队形其实就是一组数据和功能的集合.对象可以通过执行new操作符后跟要创建的对象类型的名称来创建.而创建Object类型的示例并为其添加属性和(或)方法,就可以 ...

  3. ASE "黄金点游戏"

    问题定义 黄金点游戏是源于经济学家Richar Thaler构思的在1997年伦敦金融时报进行了一次公开竞猜活动.MSRA-ASE课程的第一次结对编程中,我们写了一个AI Bot来与大家玩儿这个游戏. ...

  4. javaScript的预加载

    在有大量图片的页面中,为了避免页面加载完图片还未加载完成,我们通常会使用js的图片预加载. 这是一个预加载的demo: 首先把图片放入到一个类名为imgSrcArr的变量当中: var imgSrcA ...

  5. django post get

    GET请求和POST请求 GET请求: 1. 浏览器请求一个页面 2. 搜索引擎检索关键字的时候 POST请求: 1. 浏览器向服务端提交数据,比如登录/注册等 判断提交方式: if request. ...

  6. Center OS7网络设置

    虚拟机上设置网络连接为NAT方式(两层路由) 1:保证windows NAT 和dhcp服务启动 2:/etc/sysconfig/network-scripts/ifcfg-* TYPE=Ether ...

  7. ubuntu 安装apache2 二进制包

    官方安装教程  http://httpd.apache.org/docs/2.4/install.html 一.下载安装包 进入https://httpd.apache.org/download.cg ...

  8. vue的列表交错过渡

    参考文章 https://juejin.im/post/5cccf5b0e51d453a907b4af1

  9. logging error. UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

    根据错误提示, 找到出错的文件. 可以看到, 出错的文件是 logging 模块中的__init__.py 文件. 根据目录, 找到 这个文件, 并打开它 搜查这个文件的内容, 找'encoding' ...

  10. Sql server 2008 的完成备份和差异备份还原

    当数据库数据量不大的情况下用 Sqlserver 的完全备份就完全可以了 步骤为: 1.在需要还原的数据库上右键选择如图 2.在“常规”选项中点击“源设备”选取磁盘上备份好的.bak文件后,勾上“还原 ...