#include <iostream> #include <ctime>
using namespace std;
void sum(unsigned n,unsigned m)//构造和为n,长度为m的数列
{
if(m==0||n<=0)
{
cout<<n<<endl;
return;
}
unsigned t=(rand()%((unsigned)(n/m)));
t=(t&1)?(t-1):t;
if(!t) t+=2;
cout<<t<<"/t";
sum(n-t,m-1);
}
int main(void)
{
int n=1100,k=60;
srand((unsigned)(time(0)));
sum(n,k-1);
system("pause");
return 0;
}
构造随机数列
最新推荐文章于 2021-05-24 09:28:23 发布