题解 | #整数拆分#

整数拆分

http://www.nowcoder.com/practice/376537f4609a49d296901db5139639ec

当成完全背包求解是最容易想到的方法

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

const int N = 1e6 + 10, mod = 1000000000;

int n;
int f[N];

int main()
{
    cin >> n;
    f[0] = 1;
    for (int i = 1; i <= n; i *= 2)
        for (int j = i; j <= n; ++j)
                f[j] = (f[j] + f[j - i]) % mod;
    cout << f[n] << endl;
    return 0;
}
全部评论
为什么溢出了?
点赞 回复 分享
发布于 05-16 16:54 江苏

相关推荐

看起来名字可以很长:笑死 我暑期实习阿里云的意向也被 qq 邮箱放在垃圾箱了
点赞 评论 收藏
分享
评论
21
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务