码迷,mamicode.com
首页 > 其他好文 > 详细

SCAU 2014 group13

时间:2014-08-28 21:05:36      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   java   io   ar   for   

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?

bubuko.com,布布扣

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 * E k( 0 ~ n - 3 ) f( k );

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
const int N = 1000010;
const int mod = 1000000007;
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=0;
    while(pos>0){
        res += c[pos];
        res %= mod;
        pos -= lowbit(pos);
    }
    return res;
}
void init()
{
    update(1,1);
    update(2,2);

    ans[1] = 1;
    ans[2] = 2;

    for(int i= 3; i <=N-9 ;++i){
        LL res = ( 4*query( i-3 ) )%mod;
        res = (res + 2*ans[i-1]) % mod;
        res = (res + 5*ans[i-2]) % mod;
        ans[i] = res;
update(i,ans[i]); } }
int main() { int _,n; init(); scanf("%d",&_); while(_--){ scanf("%d",&n); printf("%lld\n",ans[n+1]); } return 0; }

 

SCAU 2014 group13

标签:style   blog   http   color   os   java   io   ar   for   

原文地址:http://www.cnblogs.com/YRETSIM/p/3942348.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!