2013年9月21日 星期六

UVA 10733 - The Colored Cubes

Problem link

Keyword: combination

Algorithm:

First calculate how many ways can the cube be colored by exactly N color.
Then use simple math to multiply C(n,i) by the methods, and you'll get the answer.
However, the hardest part is to calculate how many ways are there when exactly N colors are used. :(

Code:
#include<cstdio>
long long int C( long long int m, long long int n )
{
    long long int ans = 1;
    for( long long int i = 1; i <= n; ++i )
        ans *= m - i + 1, ans /= i;
    return ans;
}

int main()
{
    long long int n, base[ 7 ] = { 0, 1, 8, 30, 68, 75, 30 };

    while( scanf( "%lld", &n ) && n )
    {
        long long int ans = 0;
        for( long long int i = 1; i <= 6 && i <= n; ++i )
            ans += C( n, i ) * base[ i ];
        printf( "%lld\n", ans );
    }

    return 0;
}

沒有留言:

張貼留言