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);
}









share|improve this question




















  • 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

















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);
}









share|improve this question




















  • 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















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);
}









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
















  • 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



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()