Lightoj 1006 Hex-a-bonacci "Water"

Source: Internet
Author: User

FUCK!!!!! The damned question, said a large string, for fear that the code execution will time out, MD, actually is according to the code in the title, change a little bit on the line!!!!!!! Fuck, Hang,!!!!!!!!!.

Hex-a-bonacci
PDF (中文版) Statistics Forum
Time limit:0.5 second (s) Memory limit:32 MB

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", &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'll is non-negative and 0≤n≤10000 and the each of the others would be fit into a 32-bit integer.

Output

For each case, print the output of the given code. The given code may has an integer overflow problem in the compiler and so is 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:216,339

Case 2:79

Case 3:16,636

Case 4:6

Case 5:54

AC Code:

1#include <stdio.h>2#include <string.h>3 #defineH 100000074 intshu[10100], N;5 intFun ()6 {7      for(inti =0; I <6; i++)8Shu[i]%=H;9     if(N <6)Ten         returnShu[n]; One      for(inti =6; I <= N; i++) AShu[i]= (shu[i-6]+shu[i-5]+shu[i-4]+shu[i-3]+shu[i-2]+shu[i-1])%H; -     returnShu[n]; - } the intMain () - { -     intT;SCANF ("%d",&t); -      for(intj =1; J <= T; J + +) +     { -scanf"%d%d%d%d%d%d%d", &shu[0],&shu[1],&shu[2],&shu[3],&shu[4],&shu[5],&n); +         intAns =Fun (); Aprintf"Case %d:%d\n", J, ans); at     } -     return 0; -}

Lightoj 1006 Hex-a-bonacci "Water"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.