#include <iostream>
#include <ctime>
using namespace std;
int sum;
int store[10];
void Output()
{
for(int i = 9; i>=0; --i)
{
cout<<store[i]<<" ";
}
cout<<endl;
++sum;
}
void Cumput(int score, int num)
{
if(score < 0 || score > (num+1)*10 ) //次数num为0~9
return;
if(num == 0)
{
store[num] = score;
Output();
return;
}
for(int i = 0; i <= 10; ++i)
{
store[num] = i;
Cumput(score - i, num - 1);
}
}
int main(int argc, char* argv[])
{
const double begin=(double)clock()/CLK_TCK;
Cumput(90, 9);
const double end=(double)clock()/CLK_TCK;
cout<<"总数:"<<sum<<endl;
cout<<"开始时间:"<<begin<<endl;
cout<<"结束时间:"<<end<<endl;
return 0;
}
#includevoid main(){ int i1,i2,i3,i4,i5,i6,i7,i8,i9,i10;int count=0;for(i1=0;i1<10;i1++){ for(i2=0;i2<10;i2++){ for(i3=0;i3<10;i3++) { for(i4=0;i4<10;i4++) { for(i5=0;i5<10;i5++){ for(i6=0;i6<10;i6++) { for(i7=0;i7<10;i7++) { for(i8=0;i8<10;i8++){ for(i9=0;i9<10;i9++){ for(i10=0;i10<10;i10++) { if(i1+i2+i3+i4+i5+i6+i7+i8+i9+i10==90) count++; printf("%d",count); }}} } }} } }}}return;}跑很久:92 378 还是递归好用: