Cell division algorithm problem

topic

There is a cell, it divided once per second. Each new dividing cells seconds from the start of the fourth, a cell will be split per second. Please programming in the first n seconds, the total number of cells?

Entry

A plurality of test input data examples, each test case per line, comprising an integer n (0 <n <55) , n the meanings as described in the title.
n = 0 indicates the end of input data, without processing.

Export

For each test case, the number of outputs at the n seconds when cells.
Each output per line.

Thinking

The first day of a
2 ---- 2
. 3 ----. 3
. 4 ----. 4
. 5 ---- 6 = 4+ next day all of the cells and broken
. 6. 7 = 6 + third ---- All days and cell division
.
.
the number of day n ---- n-1 + n-3 days the number of days

Code

#include<iostream>
#include<vector>
using namespace std;

int main()
{
	int year;
 	cin>>year;
 	int X[1000];
 	for (int i = 1; i <= year; i++) 
	 {
		if (i == 1) {
			X[i] = 1;
		} else if (i < 5) {
			X[i] = X[i - 1] +1;
		} else {
			X[i] = (X[i - 1] + X[i - 3]);
		}
		//sum += X[i];
	}
 	cout<<X[year]; 
	return 0;
}
Published 11 original articles · won praise 1 · views 264

Guess you like

Origin blog.csdn.net/weixin_42408097/article/details/104261120