給出板球隊的比分,找到/打印所有配置/獲得比分的方法。有3種方法得分2,3和7C++中的記憶
實施例: 評分:10
輸出: (0,1,1) (0,2,2) (0,0,5 )
void out(int score, int two, int three, int seven)
{
if(score == 0)
{
cout << "(" << two << ", " << three << ", " << seven << ")" << endl;
}
else if (score < 0)
{
return;
}
else
{
outputs(score - 7, two, three, seven + 1);
outputs(score - 3, two, three + 1, seven);
outputs(score - 2, two + 1, three, seven);
}
return;
}
我得到了正確的答案,但有重複,也想使用記憶化,我感到很困惑如何實現 (0,1,1) (0,1,1) ( 2,2,0) (2,2,0) (2,2,0) (2,2,0) (2,2,0) (2,2,0) (5,0,0)
這有什麼困惑嗎? – 2014-11-22 08:56:07