给出板球队的比分,找到/打印所有配置/获得比分的方法。有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