算法分析之半数集自底向上

#include
#include
using namespace std;


int main(void)
{
	int n;
	vector hset;
	hset.push_back(1);

	while (cin >> n) {
		if (hset.size() >= n + 1)
			cout << hset[n] << endl;
		else {
			for (int i = hset.size(); i <= n; ++i) {
				int cnt = 0;
				for (int j = 0; j <= i / 2; ++j)
					cnt += hset[j];
				hset.push_back(cnt);
			}
			cout << hset[n] << endl;
		}
	}

	return 0;
}

你可能感兴趣的:(算法分析,动态规划)