标签:
Description
Input
Output
Sample Input
2 4 5 0
Sample Output
2 4 6
题解:第i年的牛(i>4)就等于3年前牛(因为这些牛在今年都会再生牛)+去年的所有牛。dp[i] = dp[i-3]+dp[i-1];
数据比较大,需要用long long
#include<cstdio> #include<cstring> #include<iostream> #include<stdlib.h> #include<vector> #include<queue> #include<cmath> using namespace std; #define maxn 100 #define oo 0x3f3f3f #define PI 3.1415926535897932 int n; int k; long long dp[maxn]; void init() { for(int i=5; i<=maxn; i++) dp[i] = dp[i-3] + dp[i-1]; } int main() { int t,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; }
标签:
原文地址:http://www.cnblogs.com/biu-biu-biu-/p/5744474.html