codevs 2549 自然数和分解

时间限制: 1 s

空间限制: 32000 KB

题目等级 : 白银 Silver

题目描述 Description

把自然数N分解为若干个自然数之和,输出方案数。

输入描述 Input Description

N,(1≤n≤50)

输出描述 Output Description

方案数

样例输入 Sample Input

5

样例输出 Sample Output

7

数据范围及提示 Data Size & Hint

5 可分为

1 1 1 1 1
1 1 1 2
1 1 3
1 2 2
1 4
2 3
5

bfs

屠龙宝刀点击就送

#include <cstdio>

int N,ans,i;
void dfs(int sum,int pos)
{
    if(sum==0)
    {
        ans++;
        return;
    }
    for(int i=pos;i<=sum;i++)
    dfs(sum-i,i);
}
int main()
{
    scanf("%d",&N);
    dfs(N,1);
    printf("%d",ans);
    return 0;
}
时间: 2024-08-27 00:46:35

codevs 2549 自然数和分解的相关文章

2549 自然数和分解

2549 自然数和分解 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 白银 Silver 题解 查看运行结果 题目描述 Description 把自然数N分解为若干个自然数之和,输出方案数. 输入描述 Input Description N,(1≤n≤50) 输出描述 Output Description 方案数 样例输入 Sample Input 5 样例输出 Sample Output 7 数据范围及提示 Data Size & Hint 5 可分为 1 1 1 1 11

自然数和分解

codevs——2549 自然数和分解 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 白银 Silver 题解 题目描述 Description 把自然数N分解为若干个自然数之和,输出方案数. 输入描述 Input Description N,(1≤n≤50) 输出描述 Output Description 方案数 样例输入 Sample Input 5 样例输出 Sample Output 7 数据范围及提示 Data Size & Hint 5 可分为 1 1 1 1 11

AC日记——自然数和分解 codevs 2549

自然数和分解 思路: 水题: 代码: #include <bits/stdc++.h> using namespace std; int n,dp[100][100]; int main() { cin>>n; dp[0][0]=1; for(int i=1;i<=n;i++) { for(int j=1;j<=i;j++) { for(int v=0;v<=j;v++) { dp[i][j]+=dp[i-j][v]; } } } int ans=0; for(i

2548 自然数积分解

2548 自然数积分解 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 把自然数N分解为若干个自然数之积,输出方案数. 输入描述 Input Description 自然数N,(1≤n≤2000000000) 输出描述 Output Description 方案数 样例输入 Sample Input 20 样例输出 Sample Output 4 数据范围及提示 Data Size & Hint 20 可分为 20 4 52

自然数积分解

[题目描述] 把自然数N分解为若干个自然数之积,输出方案数. [输入描述] 自然数N(1 ≤ n ≤ 2000000000). [输出描述] 方案数. [样例输入] 20 [样例输出] 4 [数据范围及提示] 20 可分为: 204*52*102*2*5

4.1将某个大于1的自然数n分解为其素因子的乘积

//将某个大于1的自然数n分解为其素因子的乘积 #include<iostream> using namespace std; int isprime(int i); int main() { int i,j=0,m,temp; int reserve[32]; cin>>m; temp=m; while(temp!=1) { for(i=2;i<=temp;i++) if(temp%i==0 &&isprime(i)) break; reserve[j++]

codevs 2612 最有分解方案 (贪心)

/* 数字不重复 */ #include<iostream> #include<cstdio> #include<cstring> #define maxn 2600 using namespace std; int n,ans[maxn],l,p[maxn]; void Mul(int x) { for(int i=1;i<=l;i++) ans[i]=ans[i]*x; for(int i=1;i<=l;i++) if(ans[i]>9) { an

codevs:1313 质因数分解:已知正整数 n是两个不同的质数的乘积,试求出较大的那个质数 。

#include<iostream>#include<cstdio>#include<cmath>using namespace std;int a[2];int main(){ int p,b=0; scanf("%d",&p); for(int i=2;i<=p/2;i++) { if(p%i==0) { printf("%d",p/i); return 0; } }}

深搜整理汇总

2801 LOL-盖伦的蹲草计划 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题目描述 Description 众所周知,LOL这款伟大的游戏,有个叫盖伦的英雄.他的伟大之处在于他特别喜欢蹲草丛阴人(XL:蹲草阴人也算英雄?!CZQ:没办法,个个都是这么玩的).某日,德玛西亚与诺克萨斯之间又发生了一场战斗,嘉文四世希望盖伦能带领一支K人的德玛西亚军队出战. 战斗发生在召唤师峡谷.整个召唤师峡谷被分割成M行N列的一个矩阵,矩阵中有空地和几片草丛.这几片草丛中有