hdu1085-Holding Bin-Laden Captive!

http://acm.hdu.edu.cn/showproblem.php?pid=1085

#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;
int num[ 10 ] ;
int c1[ 100000 ] , c2[ 100000 ] ;

int main()
{
	int i , j , k ;
	while( cin >> num[ 1 ] >> num[ 2 ] >> num[ 5 ] )
	{
		if( num[ 1 ] == 0 && num[ 2 ] == 0 && num[ 5 ] == 0 )
			break;
		int MAX = num[ 1 ] + num[ 2 ] * 2 + num[ 5 ] * 5 ;
		for( i = 0 ; i <= MAX ; ++i )
		{
			c1[ i ] = 0 ;
			c2[ i ] = 0 ;
		}
		for( i = 0 ; i <= num[ 1 ] ; ++i )
			c1[ i ] = 1 ;
		for( i = 0 ; i <= num[ 1 ]  ; ++i )
		{
			for( j = 0 ; j <= num[ 2 ] * 2 ; j += 2 )
				c2[ j + i ] += c1[ i ] ;
		}
		for( i = 0 ; i <= num[ 1 ] + num[ 2 ] * 2 ; ++i )
		{
			c1[ i ] = c2[ i ] ;
			c2[ i ] = 0 ;
		}
		for( i = 0 ; i <= num[ 1 ] + num[ 2 ] * 2 ; ++i )
			for( j = 0 ; j <= num[ 5 ] * 5 ; j += 5 )
			{
				c2[ i + j ] += c1[ i ] ;
			}
		for( i = 0 ; i <= MAX ; ++i )
		{
			c1[ i ] = c2[ i ] ;
			c2[ i ] = 0 ;
		}
		for( i = 0 ; i <= MAX ; ++i )
			if( !c1[ i ] )
			{
				printf( "%d\n" , i ) ;
				break ;
			}
		if( i == MAX + 1 )
			printf( "%d\n" , i ) ;
	}
	return 0 ;
}

你可能感兴趣的:(杭电,母函数)