CSU 1769 (mathematics)

Source: Internet
Author: User

1769: Want to fight? Count Me in! Everybody, come here! (3) Time limit:2 Sec Memory limit:128 MB
submit:262 solved:76
[Submit] [Status] [Web Board] Description

Now "The Legend of the Furnace Stone" This card game has swept the world. The "Black stone Flame" extension that joined the environment in 2015 brought a new deck of cards to the core card "terror of the slave owner", and this set of rules for the game was called "Slave Warfare". "The horror of the slave Lord" sound "want to fight?" Count Me in! "There must be an indelible impression in the hearts of all the" stone legends "of this age.
"The Slave Lord of Terror" is a creature with a 3-point health value that summons a new 2-point health "slave-owner" when it is fatally injured on the field (e.g., 3-point-of-life slave-owner receives 1 or 2-point damage, or 1-point-of-life slave-owner is hurt). Fatal damage (damage greater than or equal to existing health) will die directly. Another type of card can cause all mobs to inflict 1 damage (reduce 1 life), called "Whirlwind effect". Thus "the slave Lord of Terror", on the pitch, after several "whirlwind effects" may be changed from one to many, at the same time issuing the frightening voice, "Everybody, come here!" ”。
On the other hand, the legend of the Furnace Stone stipulates that there are up to 7 organisms on the field, which greatly limits the "terror of the slave-owners", "the more the more born". When a "whirlwind effect" occurs, priority is given to "terrorist slave owners" who are not fatally wounded, summoning new "terror slave owners" until the number of mobs reaches 7, no longer summoning new "terror slave owners", and then removing the "terrorist slave owners" who fall below 0 or 0 of their health. On the field there are 7 "terrorist slave Owners" with a 1 health value, and a "whirlwind effect" is followed by 0 "Horrible slave owners" on the field. Another example is that there are 6 "horrible slave Owners" with 3 lives on the field, and a "whirlwind effect" after which there are 6 "horrible slave owners" of 2 lives and 1 "terror slaves" of 3 lives. Another example is that there are 4 "horrible slave owners" of 1 lives and 2 "horrible slave Owners" of 2 lives, and a "whirlwind effect" followed by 2 life-threatening "slave-owners" and 1 1-point life "terror slaves".
In this series of topic 2 we have learned how to calculate how many "horrible slave owners" will be left after the N-whirlwind effect. Now that the game has a bug, the number of slave owners on the field is no longer limited by the 7 limit. There are some 1 lives left on the field, some 2 lives, some 3 life slaves, and now ask the slave owners to go through the N-whirlwind effect of what the scene will look like.

Input

There are multiple sets of data.
One row per set of data, Hp1,hp2,hp3,n (0<=hp1,hp2,hp3<=10^9,0<=n<=10^6)
Represents 1 Life, 2 life, 3 life slave master number, and then the number of cyclone Slash.

Output

Each group outputs the final total number of slaves (the result is 1000000007 modulo) in one line, and the format is shown in the sample.

Sample Input
1 1 1 33 3 3 2
Sample Output
1018

Push the first few items: a ' [1]=a[2],a ' [2]=a[3],a ' [3]=a[2]+a[3] sum[1] = (a[2]+a[3]) and so on: sum[2] = (a ' [2]+a ' [3]) = (a[2]+2*a[3]) ....
The coefficients of sum[k] a[2] are found to be the k-1 of the Fibonacci sequence, and the coefficients of a[3] are K. Make a table, O (1) query.
#include <iostream>#include<cstring>#include<stdio.h>#include<stdlib.h>#include<algorithm>using namespaceStd;typedefLong LongLL;ConstLL mod =1000000007;Const intN =1000005; LL Fab[n];voidinit () {fab[0] =1; fab[1] =1;  for(intI=2; i<n;i++) {Fab[i]= (fab[i-1]+fab[i-2])%MoD; }}intMain () {init ();    LL A,b,c; intK;  while(SCANF ("%lld%lld%lld%d", &a,&b,&c,&k)! =EOF) {LL ans1= fab[k-1]*b%MoD; LL Ans2= fab[k]*c%MoD; printf ("%lld\n", ((ANS1+ANS2) *2)%MoD); }    return 0;}

CSU 1769 (mathematics)

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.