Breaking a set into continuous subsets such that number of 1's are greater than number of 0's
$begingroup$
You are given a list of $0$’s and $1$’s: $B[1], B[2], . . . , B[N]$. A
sublist of this list is any contiguous segment of elements—i.e.,
$A[i], A[i + 1], . . . , A[j]$, for some $i$ and $j$.
A sublist is said to be Heavy, if the number of $1$’s in it is at
least as much as the number of $0$’s in it.
We want to partition the entire list into Heavy sublists. That is, a
valid partition is a collection of Heavy sublists, such that each of
the $N$ elements is part of exactly one of the sublists. We want to
find the number of ways of doing so.
For example, suppose $N$ was $$3 and $B = [1, 0, 1]$. Then all the
sublists in this are Heavy, except for the sublist which contains only
the second element $([0])$. The various valid partitions are as
follows:
- $( [1, 0, 1] )$
- $( [1, 0], [1] )$
- $( [1], [0, 1] )$
Since there are $3$ ways to do this, the answer for this would be $3$.
Compute the number of ways of partitioning the given list into Heavy
sublists for the following instances.
(a) $N = 8, B = [0, 1, 1, 0, 0, 1, 1, 1]—i.e., B[1] = 0, B[2] = 1, . .
. , B[8] = 1$
(b) $N = 9, B = [1, 1, 0, 0, 1, 0, 0, 1, 1]—i.e., B[1] = 1, B[2] = 1,
. . . , B[9] = 1$
(c) $N = 9, B = [1, 0, 1, 0, 1, 1, 0, 1, 1]—i.e., B[1] = 1, B[2] = 0,
. . . , B[9] = 1$
I tried considering each $0$ to be $-1$ and tried calculating all the subsets that would give me a sum $geq 0$. But we need to make sure all the partitions follow this rule. This makes my method too long and difficult to compute.
Can anyone give an idea for a better method.
combinatorics permutations computer-science
$endgroup$
add a comment |
$begingroup$
You are given a list of $0$’s and $1$’s: $B[1], B[2], . . . , B[N]$. A
sublist of this list is any contiguous segment of elements—i.e.,
$A[i], A[i + 1], . . . , A[j]$, for some $i$ and $j$.
A sublist is said to be Heavy, if the number of $1$’s in it is at
least as much as the number of $0$’s in it.
We want to partition the entire list into Heavy sublists. That is, a
valid partition is a collection of Heavy sublists, such that each of
the $N$ elements is part of exactly one of the sublists. We want to
find the number of ways of doing so.
For example, suppose $N$ was $$3 and $B = [1, 0, 1]$. Then all the
sublists in this are Heavy, except for the sublist which contains only
the second element $([0])$. The various valid partitions are as
follows:
- $( [1, 0, 1] )$
- $( [1, 0], [1] )$
- $( [1], [0, 1] )$
Since there are $3$ ways to do this, the answer for this would be $3$.
Compute the number of ways of partitioning the given list into Heavy
sublists for the following instances.
(a) $N = 8, B = [0, 1, 1, 0, 0, 1, 1, 1]—i.e., B[1] = 0, B[2] = 1, . .
. , B[8] = 1$
(b) $N = 9, B = [1, 1, 0, 0, 1, 0, 0, 1, 1]—i.e., B[1] = 1, B[2] = 1,
. . . , B[9] = 1$
(c) $N = 9, B = [1, 0, 1, 0, 1, 1, 0, 1, 1]—i.e., B[1] = 1, B[2] = 0,
. . . , B[9] = 1$
I tried considering each $0$ to be $-1$ and tried calculating all the subsets that would give me a sum $geq 0$. But we need to make sure all the partitions follow this rule. This makes my method too long and difficult to compute.
Can anyone give an idea for a better method.
combinatorics permutations computer-science
$endgroup$
$begingroup$
In order to partition $B$ into sublists, you need to choose how long the rightmost sublist is, and the partition everything else into sublists. This suggests a dynamic programming approach; let $f(k)$ be the number of ways to partition $[B[1],B[2],dots,B[k]]$, then compute $f(k)$ as the sum of $f(i)$ over all $i$ for which $[B[i+1],B[i+2],dots,B[k]]$ is heavy. Compute this in the order $f(1),f(2),dots,f(n)$. What you want is $f(n)$.
$endgroup$
– Mike Earnest
Jan 31 at 18:57
add a comment |
$begingroup$
You are given a list of $0$’s and $1$’s: $B[1], B[2], . . . , B[N]$. A
sublist of this list is any contiguous segment of elements—i.e.,
$A[i], A[i + 1], . . . , A[j]$, for some $i$ and $j$.
A sublist is said to be Heavy, if the number of $1$’s in it is at
least as much as the number of $0$’s in it.
We want to partition the entire list into Heavy sublists. That is, a
valid partition is a collection of Heavy sublists, such that each of
the $N$ elements is part of exactly one of the sublists. We want to
find the number of ways of doing so.
For example, suppose $N$ was $$3 and $B = [1, 0, 1]$. Then all the
sublists in this are Heavy, except for the sublist which contains only
the second element $([0])$. The various valid partitions are as
follows:
- $( [1, 0, 1] )$
- $( [1, 0], [1] )$
- $( [1], [0, 1] )$
Since there are $3$ ways to do this, the answer for this would be $3$.
Compute the number of ways of partitioning the given list into Heavy
sublists for the following instances.
(a) $N = 8, B = [0, 1, 1, 0, 0, 1, 1, 1]—i.e., B[1] = 0, B[2] = 1, . .
. , B[8] = 1$
(b) $N = 9, B = [1, 1, 0, 0, 1, 0, 0, 1, 1]—i.e., B[1] = 1, B[2] = 1,
. . . , B[9] = 1$
(c) $N = 9, B = [1, 0, 1, 0, 1, 1, 0, 1, 1]—i.e., B[1] = 1, B[2] = 0,
. . . , B[9] = 1$
I tried considering each $0$ to be $-1$ and tried calculating all the subsets that would give me a sum $geq 0$. But we need to make sure all the partitions follow this rule. This makes my method too long and difficult to compute.
Can anyone give an idea for a better method.
combinatorics permutations computer-science
$endgroup$
You are given a list of $0$’s and $1$’s: $B[1], B[2], . . . , B[N]$. A
sublist of this list is any contiguous segment of elements—i.e.,
$A[i], A[i + 1], . . . , A[j]$, for some $i$ and $j$.
A sublist is said to be Heavy, if the number of $1$’s in it is at
least as much as the number of $0$’s in it.
We want to partition the entire list into Heavy sublists. That is, a
valid partition is a collection of Heavy sublists, such that each of
the $N$ elements is part of exactly one of the sublists. We want to
find the number of ways of doing so.
For example, suppose $N$ was $$3 and $B = [1, 0, 1]$. Then all the
sublists in this are Heavy, except for the sublist which contains only
the second element $([0])$. The various valid partitions are as
follows:
- $( [1, 0, 1] )$
- $( [1, 0], [1] )$
- $( [1], [0, 1] )$
Since there are $3$ ways to do this, the answer for this would be $3$.
Compute the number of ways of partitioning the given list into Heavy
sublists for the following instances.
(a) $N = 8, B = [0, 1, 1, 0, 0, 1, 1, 1]—i.e., B[1] = 0, B[2] = 1, . .
. , B[8] = 1$
(b) $N = 9, B = [1, 1, 0, 0, 1, 0, 0, 1, 1]—i.e., B[1] = 1, B[2] = 1,
. . . , B[9] = 1$
(c) $N = 9, B = [1, 0, 1, 0, 1, 1, 0, 1, 1]—i.e., B[1] = 1, B[2] = 0,
. . . , B[9] = 1$
I tried considering each $0$ to be $-1$ and tried calculating all the subsets that would give me a sum $geq 0$. But we need to make sure all the partitions follow this rule. This makes my method too long and difficult to compute.
Can anyone give an idea for a better method.
combinatorics permutations computer-science
combinatorics permutations computer-science
asked Jan 31 at 18:46


Aditya DuttAditya Dutt
125
125
$begingroup$
In order to partition $B$ into sublists, you need to choose how long the rightmost sublist is, and the partition everything else into sublists. This suggests a dynamic programming approach; let $f(k)$ be the number of ways to partition $[B[1],B[2],dots,B[k]]$, then compute $f(k)$ as the sum of $f(i)$ over all $i$ for which $[B[i+1],B[i+2],dots,B[k]]$ is heavy. Compute this in the order $f(1),f(2),dots,f(n)$. What you want is $f(n)$.
$endgroup$
– Mike Earnest
Jan 31 at 18:57
add a comment |
$begingroup$
In order to partition $B$ into sublists, you need to choose how long the rightmost sublist is, and the partition everything else into sublists. This suggests a dynamic programming approach; let $f(k)$ be the number of ways to partition $[B[1],B[2],dots,B[k]]$, then compute $f(k)$ as the sum of $f(i)$ over all $i$ for which $[B[i+1],B[i+2],dots,B[k]]$ is heavy. Compute this in the order $f(1),f(2),dots,f(n)$. What you want is $f(n)$.
$endgroup$
– Mike Earnest
Jan 31 at 18:57
$begingroup$
In order to partition $B$ into sublists, you need to choose how long the rightmost sublist is, and the partition everything else into sublists. This suggests a dynamic programming approach; let $f(k)$ be the number of ways to partition $[B[1],B[2],dots,B[k]]$, then compute $f(k)$ as the sum of $f(i)$ over all $i$ for which $[B[i+1],B[i+2],dots,B[k]]$ is heavy. Compute this in the order $f(1),f(2),dots,f(n)$. What you want is $f(n)$.
$endgroup$
– Mike Earnest
Jan 31 at 18:57
$begingroup$
In order to partition $B$ into sublists, you need to choose how long the rightmost sublist is, and the partition everything else into sublists. This suggests a dynamic programming approach; let $f(k)$ be the number of ways to partition $[B[1],B[2],dots,B[k]]$, then compute $f(k)$ as the sum of $f(i)$ over all $i$ for which $[B[i+1],B[i+2],dots,B[k]]$ is heavy. Compute this in the order $f(1),f(2),dots,f(n)$. What you want is $f(n)$.
$endgroup$
– Mike Earnest
Jan 31 at 18:57
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
I think you want to use a recursive algorithm. Call a sublists starting at $B[1]$ a "prefix" and a sublist ending at $B[N]$ a "suffix." For each possible way of diving the list into a suffix and a prefix, if the prefix is heavy, recursively count the number of ways of dividing the suffix into heavy sublists. (Remember to count the division into just the suffix itself.) Add up all of these, and add $1$, for the division consisting of just the original list.
$endgroup$
$begingroup$
I am sorry if I am being stupid here, but this seems like a modification of the Brute Force approach. I mean, you can use a Dynamic Programming approach to make this recursive method faster to compute (as suggested by @MikeEarnest), but this is seems too long to be calculated on pen & paper (especially for part (a) of the problem)
$endgroup$
– Aditya Dutt
Jan 31 at 19:27
$begingroup$
It is brute force, but I would think it's perfectly adequate for such small problems.
$endgroup$
– saulspatz
Jan 31 at 19:42
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
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',
autoActivateHeartbeat: false,
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
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2fmath.stackexchange.com%2fquestions%2f3095291%2fbreaking-a-set-into-continuous-subsets-such-that-number-of-1s-are-greater-than%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
I think you want to use a recursive algorithm. Call a sublists starting at $B[1]$ a "prefix" and a sublist ending at $B[N]$ a "suffix." For each possible way of diving the list into a suffix and a prefix, if the prefix is heavy, recursively count the number of ways of dividing the suffix into heavy sublists. (Remember to count the division into just the suffix itself.) Add up all of these, and add $1$, for the division consisting of just the original list.
$endgroup$
$begingroup$
I am sorry if I am being stupid here, but this seems like a modification of the Brute Force approach. I mean, you can use a Dynamic Programming approach to make this recursive method faster to compute (as suggested by @MikeEarnest), but this is seems too long to be calculated on pen & paper (especially for part (a) of the problem)
$endgroup$
– Aditya Dutt
Jan 31 at 19:27
$begingroup$
It is brute force, but I would think it's perfectly adequate for such small problems.
$endgroup$
– saulspatz
Jan 31 at 19:42
add a comment |
$begingroup$
I think you want to use a recursive algorithm. Call a sublists starting at $B[1]$ a "prefix" and a sublist ending at $B[N]$ a "suffix." For each possible way of diving the list into a suffix and a prefix, if the prefix is heavy, recursively count the number of ways of dividing the suffix into heavy sublists. (Remember to count the division into just the suffix itself.) Add up all of these, and add $1$, for the division consisting of just the original list.
$endgroup$
$begingroup$
I am sorry if I am being stupid here, but this seems like a modification of the Brute Force approach. I mean, you can use a Dynamic Programming approach to make this recursive method faster to compute (as suggested by @MikeEarnest), but this is seems too long to be calculated on pen & paper (especially for part (a) of the problem)
$endgroup$
– Aditya Dutt
Jan 31 at 19:27
$begingroup$
It is brute force, but I would think it's perfectly adequate for such small problems.
$endgroup$
– saulspatz
Jan 31 at 19:42
add a comment |
$begingroup$
I think you want to use a recursive algorithm. Call a sublists starting at $B[1]$ a "prefix" and a sublist ending at $B[N]$ a "suffix." For each possible way of diving the list into a suffix and a prefix, if the prefix is heavy, recursively count the number of ways of dividing the suffix into heavy sublists. (Remember to count the division into just the suffix itself.) Add up all of these, and add $1$, for the division consisting of just the original list.
$endgroup$
I think you want to use a recursive algorithm. Call a sublists starting at $B[1]$ a "prefix" and a sublist ending at $B[N]$ a "suffix." For each possible way of diving the list into a suffix and a prefix, if the prefix is heavy, recursively count the number of ways of dividing the suffix into heavy sublists. (Remember to count the division into just the suffix itself.) Add up all of these, and add $1$, for the division consisting of just the original list.
answered Jan 31 at 19:01


saulspatzsaulspatz
17.2k31435
17.2k31435
$begingroup$
I am sorry if I am being stupid here, but this seems like a modification of the Brute Force approach. I mean, you can use a Dynamic Programming approach to make this recursive method faster to compute (as suggested by @MikeEarnest), but this is seems too long to be calculated on pen & paper (especially for part (a) of the problem)
$endgroup$
– Aditya Dutt
Jan 31 at 19:27
$begingroup$
It is brute force, but I would think it's perfectly adequate for such small problems.
$endgroup$
– saulspatz
Jan 31 at 19:42
add a comment |
$begingroup$
I am sorry if I am being stupid here, but this seems like a modification of the Brute Force approach. I mean, you can use a Dynamic Programming approach to make this recursive method faster to compute (as suggested by @MikeEarnest), but this is seems too long to be calculated on pen & paper (especially for part (a) of the problem)
$endgroup$
– Aditya Dutt
Jan 31 at 19:27
$begingroup$
It is brute force, but I would think it's perfectly adequate for such small problems.
$endgroup$
– saulspatz
Jan 31 at 19:42
$begingroup$
I am sorry if I am being stupid here, but this seems like a modification of the Brute Force approach. I mean, you can use a Dynamic Programming approach to make this recursive method faster to compute (as suggested by @MikeEarnest), but this is seems too long to be calculated on pen & paper (especially for part (a) of the problem)
$endgroup$
– Aditya Dutt
Jan 31 at 19:27
$begingroup$
I am sorry if I am being stupid here, but this seems like a modification of the Brute Force approach. I mean, you can use a Dynamic Programming approach to make this recursive method faster to compute (as suggested by @MikeEarnest), but this is seems too long to be calculated on pen & paper (especially for part (a) of the problem)
$endgroup$
– Aditya Dutt
Jan 31 at 19:27
$begingroup$
It is brute force, but I would think it's perfectly adequate for such small problems.
$endgroup$
– saulspatz
Jan 31 at 19:42
$begingroup$
It is brute force, but I would think it's perfectly adequate for such small problems.
$endgroup$
– saulspatz
Jan 31 at 19:42
add a comment |
Thanks for contributing an answer to Mathematics Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
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%2fmath.stackexchange.com%2fquestions%2f3095291%2fbreaking-a-set-into-continuous-subsets-such-that-number-of-1s-are-greater-than%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
$begingroup$
In order to partition $B$ into sublists, you need to choose how long the rightmost sublist is, and the partition everything else into sublists. This suggests a dynamic programming approach; let $f(k)$ be the number of ways to partition $[B[1],B[2],dots,B[k]]$, then compute $f(k)$ as the sum of $f(i)$ over all $i$ for which $[B[i+1],B[i+2],dots,B[k]]$ is heavy. Compute this in the order $f(1),f(2),dots,f(n)$. What you want is $f(n)$.
$endgroup$
– Mike Earnest
Jan 31 at 18:57