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. 基于Xilinx Zynq的计算处理平台

    基于Xilinx Zynq XC7Z045 FFG 900的高性能计算模块 本模块基于Xilinx公司的FPGA XC7Z045 FFG 9000 芯片, 支持64bitDDR3, 容量2GByte: ...

  2. vue,一路走来(2)--路由vue-router

    安装 Mint UI cnpm install mint-ui --save 如果你的项目会用到 Mint UI 里较多的组件,最简单的方法就是把它们全部引入.此时需要在入口文件 main.js 中: ...

  3. Deepin学习笔记

    更改更新源 1)sudo vim /etc/apt/sources.list 2)sudo apt-get update 3)  镜像源 http://mirrors.aliyun.com/deepi ...

  4. VMware Tool的新手简单安装

    1.打开工具栏的虚拟机,点击安装VMware tool2.打开根目录的media文件夹,打开用户名命名的文件夹,复制VMxxx.tar.gz的压缩包3.粘贴到Home,4.在终端输入tar -zxvf ...

  5. ResourceBundle读取配置文件

    import java.util.ResourceBundle; /** * Created by win7 on 2017/5/20. */public class Test1 { public s ...

  6. ERROR=(CODE=1153)

    jdbc 连接oracle数据库(10.2.0.4),应用程序报错如下: Connection refused(DESCRIPTION=(ERR=1153)(VSNNUM=169870592)(ERR ...

  7. javascript实现下拉菜单的显示与隐藏

    demo.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  8. 09.事务管理、整合jpa、整合mybatis

    事务管理 spring-boot-starter-jdbc会自动默认注入DataSourceTransactionManager spring-boot-starter-data-jpa会自动默认注入 ...

  9. Linux网络栈

    原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11394930.html OSI模型 OSI 模型把网络互联的框架分为应用层.表示层.会话层.传输层.网 ...

  10. mysql Got a packet bigger than 'max_allowed_packet' bytes

    背景 数据库备份执行SQL文件时,执行到图片表插入图片数据时错误: 错误提示:Got a packet bigger than 'max_allowed_packet' bytes 原因分析及解决 m ...