Lightoj 1006 Hex-a-bonacci
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的更多相关文章
- win10 服务(系统默认服务)注册表
---恢复内容开始--- Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services] ...
- LightOJ Beginners Problems 部分题解
相关代码请戳 https://coding.net/u/tiny656/p/LightOJ/git 1006 Hex-a-bonacci. 用数组模拟记录结果,注意取模 1008 Fibsieve's ...
- Light OJ 1006 - Hex-a-bonacci
题目链接:http://acm.hust.edu.cn/vjudge/contest/121396#problem/G http://lightoj.com/volume_showproblem.ph ...
- lightoj刷题日记
提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...
- SCNU 2015ACM新生赛初赛【1006. 3D打印】解题报告
题目链接详见SCNU 2015新生网络赛 1006. 3D打印 .出题思路来自codevs 3288. 积木大赛,属于模拟题. 首先我们把“选择从第L部分到第R部分”理 ...
- quartus和modelsim中使用mif和hex文件
.mif和.hex文件都是Quartus支持的数据文件格式,常被用作内存初始化文件.可是,M odelSim却不支持.mif文件,只支持.hex文件格式,这意味着如果你的设计采用了.mif文件 ,你的 ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
- LightOj 1298 - One Theorem, One Year(DP + 欧拉)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1298 题意:给你两个数 n, p,表示一个数是由前 k 个素数组成的,共有 n 个素数 ...
- 类型转换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__()方法切返回值 ...
随机推荐
- 初识Web框架
一.Web框架本质 Python的Web框架分为两类: 通过socket自己写程序,自己处理请求: 基于Wsgi(Web Server Gateway Interface:Web服务网关接口),处理请 ...
- var声明的成员变量和函数内声明的变量区别
1.函数内部,有var声明的是局部变量,没var的,声明的全局变量. 2.在全局作用域内声明变量时,有var 和没var声明的都是全局变量,是window的属性.通过变量var声明全局对象的属性无法通 ...
- 成为七牛云 Contributor -如何贡献 logkit 代码
logkit 是 Pandora 开源的一个通用的日志收集工具,可以将不同数据源的数据方便的发送到 Pandora 进行数据分析.除了基本的数据发送功能,logkit 还有容错.并发.监控.删除等功能 ...
- Linux(4):文件属性
文件属性: # 重点: 磁盘空间不足 和 软链接与硬链接的区别 查看文件的属性: # ls lhi 文件 [root@NEO ~]# ls -lhi /etc/hosts 130078 -rw-r-- ...
- 常见Bean映射工具分析评测及Orika介绍
原地址:http://tech.dianwoda.com/2017/11/04/gao-xing-neng-te-xing-feng-fu-de-beanying-she-gong-ju-orika/ ...
- 【BZOJ2006】超级钢琴(RMQ,priority_queue)
题意: 思路: 用三元组(i, l, r)表示右端点为i,左端点在[l, r]之间和最大的区间([l, r]保证是对于i可行右端点区间的一个子区间),我们用堆维护一些这样的三元组. 堆中初始的元素为每 ...
- C#路径,文件,目录,I/O常见操作汇总
原文发布时间为:2008-10-25 -- 来源于本人的百度文章 [由搬家工具导入] 路径,文件,目录,I/O常见操作汇总 摘要: 文件操作是程序中非常基础和重要的内容,而路径、文件、目录以及 ...
- python-web apache mod_python 模块的安装
安装apache 下载mod_python 编译安装 测试 下载mod_python,下载地址:mod_python 在GitHub 上面, 下载之后:目录结构如下: 安装依赖: #查找可安装的依赖 ...
- Dividing--hdu1059(动态规划)
Problem Description Marsha and Bill own a collection of marbles. They want to split the collection a ...
- [Bzoj2733][Hnoi2012] 永无乡(BST)(Pb_ds tree)
2733: [HNOI2012]永无乡 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 4108 Solved: 2195[Submit][Statu ...