-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsplitNumber.cpp
More file actions
50 lines (37 loc) · 853 Bytes
/
splitNumber.cpp
File metadata and controls
50 lines (37 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// Created by ButcherX on 23-12-1.
//
#include<vector>
#include<iostream>
using std::vector;
int process(vector<int> vec, int left, int right)
{
int ways = 0;
for(int i = left; i < right; i++)
{
if(vec[right] < vec[right+1])
{
vec[right]++;
vec[i]--;
ways += process(vec, i + 1, right - 1);
ways++;
}
else
break;
}
return ways;
}
int splitNumber(int number)
{
vector<int> vec(number + 1, 1);
vec[number] = INT32_MAX;
int ret = process(vec, 0, number - 1);
return ret + 1;//vec全为1也算1种,所以+1
}
//=============================================================
int main()
{
// std::cout<<splitNumber(7) << std::endl;
std::cout<<dp2(9) << std::endl;
std::cout<<process1(8, 9) << std::endl;
}