Given a code (not optimized), and necessary inputs, you have to find the output of the code for the inputs. The code is as follows:

int a, b, c, d, e, f;
int fn( int n ) {
    if( n == 0 ) return a;
    if( n == 1 ) return b;
    if( n == 2 ) return c;
    if( n == 3 ) return d;
    if( n == 4 ) return e;
    if( n == 5 ) return f;
    return( fn(n-1) + fn(n-2) + fn(n-3) + fn(n-4) + fn(n-5) + fn(n-6) );
}
int main() {
    int n, caseno = 0, cases;
    scanf("%d", &cases);
    while( cases-- ) {
        scanf("%d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &n);
        printf("Case %d: %d\n", ++caseno, fn(n) % 10000007);
    }
    return 0;
}

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case contains seven integers, a, b, c, d, e, f and n. All integers will be non-negative and 0 ≤ n ≤ 10000 and the each of the others will be fit into a 32-bit integer.

Output

For each case, print the output of the given code. The given code may have integer overflow problem in the compiler, so be careful.

Sample Input

Output for Sample Input

5

0 1 2 3 4 5 20

3 2 1 5 0 1 9

4 12 9 4 5 6 15

9 8 7 6 5 4 3

3 4 3 2 54 5 4

Case 1: 216339

Case 2: 79

Case 3: 16636

Case 4: 6

Case 5: 54

/* ***********************************************
Author :guanjun
Created Time :2016/6/10 10:54:05
File Name :1006.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 10000007
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(int a,int b){
return a>b;
}
ll dp[maxn];
ll a, b, c, d, e, f,n;
ll fn( int n ) {
if(dp[n]!=-)return dp[n];
if( n == ) return a;
if( n == ) return b;
if( n == ) return c;
if( n == ) return d;
if( n == ) return e;
if( n == ) return f;
return dp[n]=(fn(n-) + fn(n-) + fn(n-) + fn(n-) + fn(n-) + fn(n-))%mod;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int T;
cin>>T;
for(int t=;t<=T;t++){
memset(dp,-,sizeof dp);
cin>>a>>b>>c>>d>>e>>f>>n;
printf("Case %d: %lld\n", t, fn(n) % mod);
}
return ;
}

Lightoj 1006 Hex-a-bonacci的更多相关文章

  1. win10 服务(系统默认服务)注册表

    ---恢复内容开始--- Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services] ...

  2. LightOJ Beginners Problems 部分题解

    相关代码请戳 https://coding.net/u/tiny656/p/LightOJ/git 1006 Hex-a-bonacci. 用数组模拟记录结果,注意取模 1008 Fibsieve's ...

  3. Light OJ 1006 - Hex-a-bonacci

    题目链接:http://acm.hust.edu.cn/vjudge/contest/121396#problem/G http://lightoj.com/volume_showproblem.ph ...

  4. lightoj刷题日记

    提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...

  5. SCNU 2015ACM新生赛初赛【1006. 3D打印】解题报告

            题目链接详见SCNU 2015新生网络赛 1006. 3D打印 .出题思路来自codevs 3288. 积木大赛,属于模拟题.         首先我们把“选择从第L部分到第R部分”理 ...

  6. quartus和modelsim中使用mif和hex文件

    .mif和.hex文件都是Quartus支持的数据文件格式,常被用作内存初始化文件.可是,M odelSim却不支持.mif文件,只支持.hex文件格式,这意味着如果你的设计采用了.mif文件 ,你的 ...

  7. 区间DP LightOJ 1422 Halloween Costumes

    http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...

  8. LightOj 1298 - One Theorem, One Year(DP + 欧拉)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1298 题意:给你两个数 n, p,表示一个数是由前 k 个素数组成的,共有 n 个素数 ...

  9. 类型转换bin()、chr()、ord() 、int()、float()、str()、repr()、bytes()、tuple(s )、 list(s )   、unichr(x ) 、 ord(x )  、 hex(x )  、          type()数据类型查询

    1.bin() 将整数x转换为二进制字符串,如果x不为Python中int类型,x必须包含方法__index__()并且返回值为integer: 参数x:整数或者包含__index__()方法切返回值 ...

随机推荐

  1. Spring异常——BeanNotOfRequiredTypeException

    使用junit测试ssh搭建的框架的时候,遇到了一个异常: 异常消息: org.springframework.beans.factory.BeanCreationException: Error c ...

  2. [MVC][Shopping]Copy Will's Code

    数据模型规划(Models) //DisplayNameAttribute 指定属性的显示名称 [DisplayName("商品类别")] //DisplayColumnAttri ...

  3. SQLServer__问题记录

    “备份集中的数据库备份与现有的xx数据库不同”  参考链接: http://www.cnblogs.com/huangfr/archive/2012/08/09/2629687.html RESTOR ...

  4. python--如何在线上环境优雅的修改配置文件?

    1.如何在线上环境优雅的修改配置文件? 原配置文件 #原配置文件 global log 127.0.0.1 local2 daemon maxconn 256 log 127.0.0.1 local2 ...

  5. hdu 2845

    #include<stdio.h> #define N 200100 int f[N]; int  a[N],n; int main() { int m,j,i,suma,sumb,sum ...

  6. gcc,gdb基础学习1

    gcc: (1)gcc -O1 -S code.c   这里的-S可以的到code.c的汇编(只进行了预处理和编译这:两个阶段形成 了汇编代码code·s) (2)gcc -c code.c   这里 ...

  7. MITM Proxy环境搭建

    MITM_Proxy环境搭建 环境要求 系统环境要求: Ubuntu 14.04 x64,CentOS 7 x64以上版本系统(建议使用xubuntu 14.04 x64,稳定硬件要求低) Pytho ...

  8. django学习之- session

    session和cookie关系:session依赖于cookie基于cookie做用户验证时,敏感信息不适合放在cookie中原理:cookie定义:保存在用户游览器端的键值对session定义:保 ...

  9. 【webstorm 系列之一】快捷键很好用啊

    书签 bookmarks , 在多文件中调试很方便 断点只能在js文件中用,而bookmark可以在所有文件中使用 书签开关 F11  (给光标所在行加书签) 显示书签 Shift + F11 书签号 ...

  10. Fractal---POJ2083(dfs)

    http://poj.org/problem?id=2083 一道我认为有点恶心的dfs       刚开始没有初始化  用G++交  一直TLE  后来用了C++竟然是wa   那这肯定是我的问题了 ...