您的位置:首页 > 其它

Ural1079-Maximum

2016-11-15 15:22 253 查看
递归预处理

#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn = 100000 + 5;

int a[maxn];

int f(int x) {
if (x == 0 || (x != 0 && a[x])) {
return a[x];
}
if (x % 2 == 0) {
return f(x/2);
} else {
return f((x-1)/2) + f((x-1)/2+1);
}
}

int main(int argc, char const *argv[]) {
a[0] = 0;
a[1] = 1;
for (int i = 2; i < 100000; i++) {
a[i] = f(i);
}
int n;
while (scanf("%d", &n) == 1 && n) {
printf("%d\n", *max_element(a, a + n + 1));
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: