How to use nPn in Burst Balloon problem with the given condition?












1














I was trying to understand this problem Burst Balloon . Mainly selecting the most efficient balloon to burst from the given condition. Given conditions are :
Below is the condition to calculate the score.




  1. When Balloon $B_i$ Explodes then score will be a product of $B_{i-1}$ & $B_{i+1}$ (score ${}= B_{i-1}times B_{i+1}$).


  2. When Balloon $B_i$ Explodes and there is only left Balloon present then score will be $B_{i-1}$.


  3. When Balloon $B_i$ Explodes and there is only right Balloon present then score will be $B_{i+1}$.



  4. When Balloon $B_i$ explodes and there is no left and right Balloon present then score will be $B_i$.



    Example:



    Input: B = {1, 2, 3, 4}



    Output: 20



    Explanation:



    For max score:



    3 explodes, score= 4*2=8 (product of adjacent balloons)



    2 explodes score= 4*1 + 8 = 12 (product of adjacent balloons)



    1 explodes score= 4 + 12= 16 (only 4 is left on the left side)



    4 explodes score = 4 + 16 = 20 (no balloons left so add 4)



    score =20



    other combinations will result in lesser scores.
    No sorting is allowed




But when I tried to apply this on this input n = 6
values = 7, 10, 8, 20, 50, 9.



In my opinion it should be = 1331
by using 20, 8, 10, 50, 7, 9 ballons.



I've used this nPn ways (1st balloon N ways, 2nd N-1 ways …last balloon 1 ways N*(N-1)(N-2)..2*1= N! to select balloons.



But from the geekforgeeks code this output is 1400. I'm unable to understand how can be this 1400? I know this is not pure mathematical problem because it's programming related problem.



But I'm confused how this combination is actually selected










share|cite|improve this question
























  • Welcome to MSE. For some basic information about writing mathematics at this site see, e.g., basic help on mathjax notation, mathjax tutorial and quick reference, main meta site math tutorial and equation editing how-to.
    – José Carlos Santos
    Nov 23 '18 at 8:37
















1














I was trying to understand this problem Burst Balloon . Mainly selecting the most efficient balloon to burst from the given condition. Given conditions are :
Below is the condition to calculate the score.




  1. When Balloon $B_i$ Explodes then score will be a product of $B_{i-1}$ & $B_{i+1}$ (score ${}= B_{i-1}times B_{i+1}$).


  2. When Balloon $B_i$ Explodes and there is only left Balloon present then score will be $B_{i-1}$.


  3. When Balloon $B_i$ Explodes and there is only right Balloon present then score will be $B_{i+1}$.



  4. When Balloon $B_i$ explodes and there is no left and right Balloon present then score will be $B_i$.



    Example:



    Input: B = {1, 2, 3, 4}



    Output: 20



    Explanation:



    For max score:



    3 explodes, score= 4*2=8 (product of adjacent balloons)



    2 explodes score= 4*1 + 8 = 12 (product of adjacent balloons)



    1 explodes score= 4 + 12= 16 (only 4 is left on the left side)



    4 explodes score = 4 + 16 = 20 (no balloons left so add 4)



    score =20



    other combinations will result in lesser scores.
    No sorting is allowed




But when I tried to apply this on this input n = 6
values = 7, 10, 8, 20, 50, 9.



In my opinion it should be = 1331
by using 20, 8, 10, 50, 7, 9 ballons.



I've used this nPn ways (1st balloon N ways, 2nd N-1 ways …last balloon 1 ways N*(N-1)(N-2)..2*1= N! to select balloons.



But from the geekforgeeks code this output is 1400. I'm unable to understand how can be this 1400? I know this is not pure mathematical problem because it's programming related problem.



But I'm confused how this combination is actually selected










share|cite|improve this question
























  • Welcome to MSE. For some basic information about writing mathematics at this site see, e.g., basic help on mathjax notation, mathjax tutorial and quick reference, main meta site math tutorial and equation editing how-to.
    – José Carlos Santos
    Nov 23 '18 at 8:37














1












1








1







I was trying to understand this problem Burst Balloon . Mainly selecting the most efficient balloon to burst from the given condition. Given conditions are :
Below is the condition to calculate the score.




  1. When Balloon $B_i$ Explodes then score will be a product of $B_{i-1}$ & $B_{i+1}$ (score ${}= B_{i-1}times B_{i+1}$).


  2. When Balloon $B_i$ Explodes and there is only left Balloon present then score will be $B_{i-1}$.


  3. When Balloon $B_i$ Explodes and there is only right Balloon present then score will be $B_{i+1}$.



  4. When Balloon $B_i$ explodes and there is no left and right Balloon present then score will be $B_i$.



    Example:



    Input: B = {1, 2, 3, 4}



    Output: 20



    Explanation:



    For max score:



    3 explodes, score= 4*2=8 (product of adjacent balloons)



    2 explodes score= 4*1 + 8 = 12 (product of adjacent balloons)



    1 explodes score= 4 + 12= 16 (only 4 is left on the left side)



    4 explodes score = 4 + 16 = 20 (no balloons left so add 4)



    score =20



    other combinations will result in lesser scores.
    No sorting is allowed




But when I tried to apply this on this input n = 6
values = 7, 10, 8, 20, 50, 9.



In my opinion it should be = 1331
by using 20, 8, 10, 50, 7, 9 ballons.



I've used this nPn ways (1st balloon N ways, 2nd N-1 ways …last balloon 1 ways N*(N-1)(N-2)..2*1= N! to select balloons.



But from the geekforgeeks code this output is 1400. I'm unable to understand how can be this 1400? I know this is not pure mathematical problem because it's programming related problem.



But I'm confused how this combination is actually selected










share|cite|improve this question















I was trying to understand this problem Burst Balloon . Mainly selecting the most efficient balloon to burst from the given condition. Given conditions are :
Below is the condition to calculate the score.




  1. When Balloon $B_i$ Explodes then score will be a product of $B_{i-1}$ & $B_{i+1}$ (score ${}= B_{i-1}times B_{i+1}$).


  2. When Balloon $B_i$ Explodes and there is only left Balloon present then score will be $B_{i-1}$.


  3. When Balloon $B_i$ Explodes and there is only right Balloon present then score will be $B_{i+1}$.



  4. When Balloon $B_i$ explodes and there is no left and right Balloon present then score will be $B_i$.



    Example:



    Input: B = {1, 2, 3, 4}



    Output: 20



    Explanation:



    For max score:



    3 explodes, score= 4*2=8 (product of adjacent balloons)



    2 explodes score= 4*1 + 8 = 12 (product of adjacent balloons)



    1 explodes score= 4 + 12= 16 (only 4 is left on the left side)



    4 explodes score = 4 + 16 = 20 (no balloons left so add 4)



    score =20



    other combinations will result in lesser scores.
    No sorting is allowed




But when I tried to apply this on this input n = 6
values = 7, 10, 8, 20, 50, 9.



In my opinion it should be = 1331
by using 20, 8, 10, 50, 7, 9 ballons.



I've used this nPn ways (1st balloon N ways, 2nd N-1 ways …last balloon 1 ways N*(N-1)(N-2)..2*1= N! to select balloons.



But from the geekforgeeks code this output is 1400. I'm unable to understand how can be this 1400? I know this is not pure mathematical problem because it's programming related problem.



But I'm confused how this combination is actually selected







algorithms permutations combinations programming






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Nov 24 '18 at 7:10







Anzum A

















asked Nov 23 '18 at 8:22









Anzum AAnzum A

85




85












  • Welcome to MSE. For some basic information about writing mathematics at this site see, e.g., basic help on mathjax notation, mathjax tutorial and quick reference, main meta site math tutorial and equation editing how-to.
    – José Carlos Santos
    Nov 23 '18 at 8:37


















  • Welcome to MSE. For some basic information about writing mathematics at this site see, e.g., basic help on mathjax notation, mathjax tutorial and quick reference, main meta site math tutorial and equation editing how-to.
    – José Carlos Santos
    Nov 23 '18 at 8:37
















Welcome to MSE. For some basic information about writing mathematics at this site see, e.g., basic help on mathjax notation, mathjax tutorial and quick reference, main meta site math tutorial and equation editing how-to.
– José Carlos Santos
Nov 23 '18 at 8:37




Welcome to MSE. For some basic information about writing mathematics at this site see, e.g., basic help on mathjax notation, mathjax tutorial and quick reference, main meta site math tutorial and equation editing how-to.
– José Carlos Santos
Nov 23 '18 at 8:37










1 Answer
1






active

oldest

votes


















0














Your last three moves are wrong. The position before these moves is ${7,50,9}$ and you burst $50$ scoring $63$, then $7$ scoring $9$, then $9$ scoring $9$, for $81$. But you can do better by bursting $7$ (scoring $50$) then $9$ (scoring $50$) then $50$ (scoring $50$) for $150$.



The point here is that it isn't always best to make the highest scoring move, because it may remove good options for future moves. (In other words, the greedy algorithm is not optimal.)






share|cite|improve this answer





















  • okay, I got this. This is a greedy problem
    – Anzum A
    Nov 23 '18 at 8:51











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


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3010109%2fhow-to-use-npn-in-burst-balloon-problem-with-the-given-condition%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









0














Your last three moves are wrong. The position before these moves is ${7,50,9}$ and you burst $50$ scoring $63$, then $7$ scoring $9$, then $9$ scoring $9$, for $81$. But you can do better by bursting $7$ (scoring $50$) then $9$ (scoring $50$) then $50$ (scoring $50$) for $150$.



The point here is that it isn't always best to make the highest scoring move, because it may remove good options for future moves. (In other words, the greedy algorithm is not optimal.)






share|cite|improve this answer





















  • okay, I got this. This is a greedy problem
    – Anzum A
    Nov 23 '18 at 8:51
















0














Your last three moves are wrong. The position before these moves is ${7,50,9}$ and you burst $50$ scoring $63$, then $7$ scoring $9$, then $9$ scoring $9$, for $81$. But you can do better by bursting $7$ (scoring $50$) then $9$ (scoring $50$) then $50$ (scoring $50$) for $150$.



The point here is that it isn't always best to make the highest scoring move, because it may remove good options for future moves. (In other words, the greedy algorithm is not optimal.)






share|cite|improve this answer





















  • okay, I got this. This is a greedy problem
    – Anzum A
    Nov 23 '18 at 8:51














0












0








0






Your last three moves are wrong. The position before these moves is ${7,50,9}$ and you burst $50$ scoring $63$, then $7$ scoring $9$, then $9$ scoring $9$, for $81$. But you can do better by bursting $7$ (scoring $50$) then $9$ (scoring $50$) then $50$ (scoring $50$) for $150$.



The point here is that it isn't always best to make the highest scoring move, because it may remove good options for future moves. (In other words, the greedy algorithm is not optimal.)






share|cite|improve this answer












Your last three moves are wrong. The position before these moves is ${7,50,9}$ and you burst $50$ scoring $63$, then $7$ scoring $9$, then $9$ scoring $9$, for $81$. But you can do better by bursting $7$ (scoring $50$) then $9$ (scoring $50$) then $50$ (scoring $50$) for $150$.



The point here is that it isn't always best to make the highest scoring move, because it may remove good options for future moves. (In other words, the greedy algorithm is not optimal.)







share|cite|improve this answer












share|cite|improve this answer



share|cite|improve this answer










answered Nov 23 '18 at 8:30









Especially LimeEspecially Lime

21.7k22858




21.7k22858












  • okay, I got this. This is a greedy problem
    – Anzum A
    Nov 23 '18 at 8:51


















  • okay, I got this. This is a greedy problem
    – Anzum A
    Nov 23 '18 at 8:51
















okay, I got this. This is a greedy problem
– Anzum A
Nov 23 '18 at 8:51




okay, I got this. This is a greedy problem
– Anzum A
Nov 23 '18 at 8:51


















draft saved

draft discarded




















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3010109%2fhow-to-use-npn-in-burst-balloon-problem-with-the-given-condition%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







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents