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个城市里跑来跑去.最后一天达到城市 ...
随机推荐
- Checklist: 2019 05.01 ~ 06.30
Golang Lessons learned porting 50k loc from Java to Go Five things that make Go fast Simple techniqu ...
- YouCompleteMe报错可能是第三方库没有
git submodule update --init --recursive 到YouCompleteMe安装目录下,执行上面的命令
- worldcloud库的使用
worldcloud库的使用 worldcloud是一个优秀的第三方词云展示库,用来实现比较有逼格的数据可视化效果.更加直观与艺术的展示单词. worldcloud对象的创建 worldcloud.W ...
- vue,一路走来(7)--响应路由参数的变化
今天描述的问题估计会有很多人也遇到过. vue-router多个路由地址绑定一个组件造成created不执行 也就是文档描述的,如下图 我的解决方案: created () { console.log ...
- Sass函数:数学函数-abs函数
abs( ) 函数会返回一个数的绝对值. >> abs(10) 10 >> abs(-10) 10 >> abs(-10px) 10px >> abs( ...
- java ArrayList练习题
package java06; /* *随机产生6的1——33的数字,并存储到列表中,再进行遍历 * */ import java.util.ArrayList; import java.util.R ...
- CF960G Bandit Blues 第一类斯特林数+分治+FFT
题目传送门 https://codeforces.com/contest/960/problem/G 题解 首先整个排列的最大值一定是 \(A\) 个前缀最大值的最后一个,也是 \(B\) 个后缀最大 ...
- ARC096E Everything on It 容斥原理
题目传送门 https://atcoder.jp/contests/arc096/tasks/arc096_c 题解 考虑容斥,问题转化为求至少有 \(i\) 个数出现不高于 \(1\) 次. 那么我 ...
- 1.xml简单介绍
1.xml(eXtensible Markup Language)的简介 (1)xml: 可扩展标记型语言 - 标记型语言:例如html也是标记型语言,也是使用标签来操作的 - 可扩展:html里面的 ...
- This MySqlConnection is already in use
项目中类似于以下的代码,实际的代码要更复杂,DbContext是依赖注入的: 报错如下: This MySqlConnection is already in use. See https://fl. ...