#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
const int value[] = {1, 2, 5, 10, 20, 50, 100, 200 };
const int n = sizeof(value) / sizeof(value[0]);
const int M = 200;
vector<int> ways(M+1);
fill( ways.begin(), ways.end(), 0 );
ways[0] = 1;
vector<int> ways_tmp;
for ( int i = 0; i < n; ++i )
{
ways_tmp = ways;
for ( int j = 0; j <= M - value[i]; ++j )
{
int k = j + value[i];
while ( k <= M )
{
ways_tmp[k] += ways[j];
k += value[i];
}
}
ways.swap( ways_tmp );
}
cout << ways[M] << endl;
return 0;
}
http://projecteuler.net/problem=31 [Answer:73682]
最新推荐文章于 2011-12-08 22:42:44 发布