how can i separate number by plus other unique number?
up vote
-3
down vote
favorite
i have a problem that i have to split that number to others positive number(all are unique)
for example 6=6=5+1=1+2+3=4+2 so we have 4 ways, 5=5=4+1=3+2 so we have 3 ways, i think about
recursive
for example is 6 my idea is from a starter point is 0, i have 0+(6,0) then recursive 0+(5,1) then 0+(4,2) then 0+ (3,3) 3,3
is wrong because numbers are unique, then move to 1 like
1+ (5,1) but is same as above,like 1+4+1 is wrong how can i do this problem?, please give an idea or for example for me, thanks a lots. i have been making this problem for 4 days but nothing happen,I'm using c++
i didn't write code yet, because i though it wrong, but here is my fast code:
#include <iostream>
using namespace std;
int count=1;
int recursive (int n,int k)
{
if(k>=n)
{
return 0;
}
count++;
for(int i=k;i<n;i++) {
recursive(n-i,i+1);
}
return count;
}
int main()
{
int n;
cin>>n;
cout<< recursive (n,0);
}
c++ recursion
|
show 8 more comments
up vote
-3
down vote
favorite
i have a problem that i have to split that number to others positive number(all are unique)
for example 6=6=5+1=1+2+3=4+2 so we have 4 ways, 5=5=4+1=3+2 so we have 3 ways, i think about
recursive
for example is 6 my idea is from a starter point is 0, i have 0+(6,0) then recursive 0+(5,1) then 0+(4,2) then 0+ (3,3) 3,3
is wrong because numbers are unique, then move to 1 like
1+ (5,1) but is same as above,like 1+4+1 is wrong how can i do this problem?, please give an idea or for example for me, thanks a lots. i have been making this problem for 4 days but nothing happen,I'm using c++
i didn't write code yet, because i though it wrong, but here is my fast code:
#include <iostream>
using namespace std;
int count=1;
int recursive (int n,int k)
{
if(k>=n)
{
return 0;
}
count++;
for(int i=k;i<n;i++) {
recursive(n-i,i+1);
}
return count;
}
int main()
{
int n;
cin>>n;
cout<< recursive (n,0);
}
c++ recursion
2
seems like you already have an idea for an algorithm, why dont you write some code to see how it does?
– user463035818
Nov 7 at 9:27
Your starter point should be 1 and the next number must be bigger than the current number to ensure uniqueness
– Thomas Sablik
Nov 7 at 9:28
i have but problem is my idea is probably not effective, because it must have unique number
– Quốc Khánh Lê
Nov 7 at 9:29
efficiency should be your last concern when implmenting version zero. If you dont want solutions where a number appears twice, just skip them
– user463035818
Nov 7 at 9:30
As I if your numbers are strictly increasing than your solutions will be unique. 1+5 will be a valid solution but 5+1 won't.
– Thomas Sablik
Nov 7 at 9:31
|
show 8 more comments
up vote
-3
down vote
favorite
up vote
-3
down vote
favorite
i have a problem that i have to split that number to others positive number(all are unique)
for example 6=6=5+1=1+2+3=4+2 so we have 4 ways, 5=5=4+1=3+2 so we have 3 ways, i think about
recursive
for example is 6 my idea is from a starter point is 0, i have 0+(6,0) then recursive 0+(5,1) then 0+(4,2) then 0+ (3,3) 3,3
is wrong because numbers are unique, then move to 1 like
1+ (5,1) but is same as above,like 1+4+1 is wrong how can i do this problem?, please give an idea or for example for me, thanks a lots. i have been making this problem for 4 days but nothing happen,I'm using c++
i didn't write code yet, because i though it wrong, but here is my fast code:
#include <iostream>
using namespace std;
int count=1;
int recursive (int n,int k)
{
if(k>=n)
{
return 0;
}
count++;
for(int i=k;i<n;i++) {
recursive(n-i,i+1);
}
return count;
}
int main()
{
int n;
cin>>n;
cout<< recursive (n,0);
}
c++ recursion
i have a problem that i have to split that number to others positive number(all are unique)
for example 6=6=5+1=1+2+3=4+2 so we have 4 ways, 5=5=4+1=3+2 so we have 3 ways, i think about
recursive
for example is 6 my idea is from a starter point is 0, i have 0+(6,0) then recursive 0+(5,1) then 0+(4,2) then 0+ (3,3) 3,3
is wrong because numbers are unique, then move to 1 like
1+ (5,1) but is same as above,like 1+4+1 is wrong how can i do this problem?, please give an idea or for example for me, thanks a lots. i have been making this problem for 4 days but nothing happen,I'm using c++
i didn't write code yet, because i though it wrong, but here is my fast code:
#include <iostream>
using namespace std;
int count=1;
int recursive (int n,int k)
{
if(k>=n)
{
return 0;
}
count++;
for(int i=k;i<n;i++) {
recursive(n-i,i+1);
}
return count;
}
int main()
{
int n;
cin>>n;
cout<< recursive (n,0);
}
c++ recursion
c++ recursion
edited Nov 7 at 9:38
asked Nov 7 at 9:25
Quốc Khánh Lê
184
184
2
seems like you already have an idea for an algorithm, why dont you write some code to see how it does?
– user463035818
Nov 7 at 9:27
Your starter point should be 1 and the next number must be bigger than the current number to ensure uniqueness
– Thomas Sablik
Nov 7 at 9:28
i have but problem is my idea is probably not effective, because it must have unique number
– Quốc Khánh Lê
Nov 7 at 9:29
efficiency should be your last concern when implmenting version zero. If you dont want solutions where a number appears twice, just skip them
– user463035818
Nov 7 at 9:30
As I if your numbers are strictly increasing than your solutions will be unique. 1+5 will be a valid solution but 5+1 won't.
– Thomas Sablik
Nov 7 at 9:31
|
show 8 more comments
2
seems like you already have an idea for an algorithm, why dont you write some code to see how it does?
– user463035818
Nov 7 at 9:27
Your starter point should be 1 and the next number must be bigger than the current number to ensure uniqueness
– Thomas Sablik
Nov 7 at 9:28
i have but problem is my idea is probably not effective, because it must have unique number
– Quốc Khánh Lê
Nov 7 at 9:29
efficiency should be your last concern when implmenting version zero. If you dont want solutions where a number appears twice, just skip them
– user463035818
Nov 7 at 9:30
As I if your numbers are strictly increasing than your solutions will be unique. 1+5 will be a valid solution but 5+1 won't.
– Thomas Sablik
Nov 7 at 9:31
2
2
seems like you already have an idea for an algorithm, why dont you write some code to see how it does?
– user463035818
Nov 7 at 9:27
seems like you already have an idea for an algorithm, why dont you write some code to see how it does?
– user463035818
Nov 7 at 9:27
Your starter point should be 1 and the next number must be bigger than the current number to ensure uniqueness
– Thomas Sablik
Nov 7 at 9:28
Your starter point should be 1 and the next number must be bigger than the current number to ensure uniqueness
– Thomas Sablik
Nov 7 at 9:28
i have but problem is my idea is probably not effective, because it must have unique number
– Quốc Khánh Lê
Nov 7 at 9:29
i have but problem is my idea is probably not effective, because it must have unique number
– Quốc Khánh Lê
Nov 7 at 9:29
efficiency should be your last concern when implmenting version zero. If you dont want solutions where a number appears twice, just skip them
– user463035818
Nov 7 at 9:30
efficiency should be your last concern when implmenting version zero. If you dont want solutions where a number appears twice, just skip them
– user463035818
Nov 7 at 9:30
As I if your numbers are strictly increasing than your solutions will be unique. 1+5 will be a valid solution but 5+1 won't.
– Thomas Sablik
Nov 7 at 9:31
As I if your numbers are strictly increasing than your solutions will be unique. 1+5 will be a valid solution but 5+1 won't.
– Thomas Sablik
Nov 7 at 9:31
|
show 8 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53186594%2fhow-can-i-separate-number-by-plus-other-unique-number%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
seems like you already have an idea for an algorithm, why dont you write some code to see how it does?
– user463035818
Nov 7 at 9:27
Your starter point should be 1 and the next number must be bigger than the current number to ensure uniqueness
– Thomas Sablik
Nov 7 at 9:28
i have but problem is my idea is probably not effective, because it must have unique number
– Quốc Khánh Lê
Nov 7 at 9:29
efficiency should be your last concern when implmenting version zero. If you dont want solutions where a number appears twice, just skip them
– user463035818
Nov 7 at 9:30
As I if your numbers are strictly increasing than your solutions will be unique. 1+5 will be a valid solution but 5+1 won't.
– Thomas Sablik
Nov 7 at 9:31