//
for ( int a = 1 ; a <= 18 ; a ++ )
for ( int b = a + 1 ; b <= ( 94 - a) / 4 ; b ++ )
for ( int c = b + 1 ; c <= ( 97 - a - b) / 3 ; c ++ )
{
int k = 50 - a - b - c;
if (k < c + 1 ) k = c + 1 ;
for ( int d = k; d <= ( 99 - a - b - c) / 2 ; d ++ )
{
int e = 100 - (a + b + c + d);
Console . WriteLine( "{0},{1},{2},{3},{4}" , a, b, c, d, e);
}
}
//
public List < string > StringList = new List < string > ();
public void Combination( List < int > ALeft, List < int > ARight, int ASum, string APath)
{
if (ALeft . Count >= 5 )
{
if (ASum == 100 ) StringList . Add(APath);
return ;
}
if (ARight . Count <= 0 ) return ;
for ( int i = 0 ; i < ARight . Count; i ++ )
{
if ((ASum + ARight[i]) > 100 ) return ;
List < int > vLeft = ALeft . GetRange( 0 , ALeft . Count);
List < int > vRight = ARight . GetRange( 0 , ARight . Count);
vLeft . Add(ARight[i]);
vRight . RemoveRange( 0 , i + 1 );
Combination(vLeft, vRight, ASum + ARight[i],
APath + "+" + ARight[i] . ToString());
}
}
private void button1_Click( object sender , EventArgs e)
{
List < int > vList = new List < int > ();
for ( int i = 1 ; i <= 50 ; i ++ ) vList . Add(i);
Combination( new List < int > (), vList, 0 , "" );
Text = StringList . Count . ToString(); //18583
}