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. 【记录】微信emoji表情存入数据库

    最近遇到一个问题,在微信授权获取用户信息的时候,由于微信昵称(nickName)是表情,无法存入数据库. 查其原因,原来是因为数据库的编码格式不正确,我的是utf-8 改成utf8mb4就可以了. 其 ...

  2. CodeForces - 343D 树链剖分

    题目链接:http://codeforces.com/problemset/problem/343/D 题意:给定一棵n个n-1条边的树,起初所有节点权值为0,然后m个操作. 1 x:把x为根的子树的 ...

  3. python路径引用r的含义

    input_file = r"C:\Users\Administrator\Desktop\python-master\csv\supplier_data.csv"#r代表不转义, ...

  4. 【Leetcode周赛】从contest-51开始。(一般是10个contest写一篇文章)

    Contest 51 (2018年11月22日,周四早上)(题号681-684) 链接:https://leetcode.com/contest/leetcode-weekly-contest-51 ...

  5. JSP项目中使用ueditor(百度编辑器)

    1. 从http://ueditor.baidu.com下载JSP版本的ueditor,注意GBK和UTF-8两种版本. 2. 在Web Project项目的WebRoot目录下新增thirdpart ...

  6. bzoj1004 [HNOI2008]Cards Burnside 引理+背包

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=1004 题解 直接 Burnside 引理就可以了. 要计算不动点的个数,那么对于一个长度为 \ ...

  7. ARC101E Ribbons on Tree 容斥原理+dp

    题目链接 https://atcoder.jp/contests/arc101/tasks/arc101_c 题解 直接容斥.题目要求每一条边都被覆盖,那么我们就容斥至少有几条边没有被覆盖. 那么没有 ...

  8. hdu 2665 Kth number (poj 2104 K-th Number) 划分树

    划分树的基本功能是,对一个给定的数组,求区间[l,r]内的第k大(小)数. 划分树的基本思想是分治,每次查询复杂度为O(log(n)),n是数组规模. 具体原理见http://baike.baidu. ...

  9. 人生苦短_我用Python_类与对象的概念_006

    Python类与对象的概念类和对象--->万事万物都对象物以类聚.人以群分 --->?划分标准性别分 男女 中性成绩分 优秀 良好 不及格 类->根据类的属性来划分类的实例-> ...

  10. HDU 6034 Balala Power! —— Multi-University Training 1

    Talented Mr.Tang has nn strings consisting of only lower case characters. He wants to charge them wi ...