早教吧 育儿知识 作业答案 考试题库 百科 知识分享

这道题求oj题超时,求简单算法划分方法TimeLimit:1000MSMemoryLimit:65536KTotalSubmit:105Accepted:30Description我们知道:15=7+8=4+5+6=1+2+3+4+5,这里有3中分割方法,记dw(15)=3.把n分成一些连续的正整数和的

题目详情
这道题求oj题超时,求简单算法
划分方法
Time Limit:1000MS Memory Limit:65536K
Total Submit:105 Accepted:30
Description
我们知道: 15=7+8=4+5+6=1+2+3+4+5 , 这里有3中分割方法, 记 dw(15)=3.
把n分成一些连续的正整数和的方法数称为dw(n)
Input
多组测试数据,每组一个int型的n(n>0)
Output
输出dw(n)
Sample Input
13
15
Sample Output
1
3
Source
军哥
我写的代码:
#include
using namespace std;
int fun(int n)
{
int sum=0,i,j;
for(i=1;in)
cout
▼优质解答
答案和解析
#include
#include
using namespace std;
int fun(int n)
{
int sum=0,i,j,m;
m = (-1 + sqrt(1.0+(n