A-the story of the cow

Source: Internet
Author: User

Description

There is a cow, which has a small cow at the beginning of each year. Each heifer starts its fourth year with a heifer. Please program implementation how many cows are there in the first n years?

Input

The input data consists of multiple test instances, one for each test instance, including an integer n (0<n<55), and the meaning of n as described in the topic.
N=0 indicates the end of the input data and does not handle it.

Output

For each test instance, output the number of cows in the nth year.
Each output occupies one row.

Sample Input

2450

Sample Output

246
The puzzle: The Cattle (i>4) of the first year is equal to 3 years ago (because these cows will regenerate cows this year) + all cows last year. Dp[i] = dp[i-3]+dp[i-1];
Data is large, need to use a long long
#include <cstdio>#include<cstring>#include<iostream>#include<stdlib.h>#include<vector>#include<queue>#include<cmath>using namespacestd;#defineMAXN 100#defineOO 0x3f3f3f#definePI 3.1415926535897932intN;intK;Long LongDP[MAXN];voidinit () { for(intI=5; i<=maxn; i++) Dp[i]= dp[i-3] + dp[i-1];}intMain () {intt,m;  while(SCANF ("%d",&m), m) {dp[1] =1; dp[2] =2; dp[3] =3; dp[4] =4;        Init (); printf ("%i64d\n", Dp[m]); }    return 0;}

A-the story of the cow

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.