分类: C/C++
2009-10-15 11:23:50
1:打靶问题:靶有10环,打10次共90环有多少种情形?
#include
#include
using namespace std;
int sum;
int store[10];
ofstream out("out.txt");
void print()
{
for(int i = 0; i < 10; ++i)
out<
out<
++sum;
}
void GetArran(int target, int count)
{
if((target < 0)||(target > count*10))
return;
if(count == 1)
{
store[count-1] = target;
print();
return;
}
for(int i = 0; i <= 10; ++i)
{
store[count-1] = i;
GetArran(target - i, count - 1);
}
}
void main()
{
GetArran(90, 10);
out<<"总数:"<
}
2:求用1、2、5这三个数组合成100的组合个数?
#include
using namespace std;
void main()
{
int count = 0;
for(int i = 0; i <= 100; i += 5)
count += (i + 2)/2;
cout<
}