#include <iostream>
#include <map>
#include <set>
#include <stdio.h>
int cost[201] = {};
std::map< int, std::set<int> > intermediate_exp;
void ComputeBinaryExponentiation()
{
cost[1] = 0;
intermediate_exp[1].insert(1);
for (int k = 2; k <= 200; k++)
{
long long min_cost_so_far = k;
long long min_cost_pos = 0;
for (int i = 1; i <= k/2; i++)
{
if (intermediate_exp[k-i].find(i) ==
intermediate_exp[k-i].end())
{
continue;
}
if (cost[k-i] < min_cost_so_far)
{
min_cost_so_far = cost[k-i];
min_cost_pos = i;
}
}
cost[k] = min_cost_so_far + 1;
std::set<int>::iterator it;
for (it = intermediate_exp[k - min_cost_pos].begin();
it != intermediate_exp[k - min_cost_pos].end(); it++)
{
intermediate_exp[k].insert(*it);
}
intermediate_exp[k].insert(k);
}
}
int GetBinaryCount(long long k)
{
return intermediate_exp[k].size() - 1;
}
int GetCountLowerBound()
{
long long bound = 0;
long long power = 0;
long long base = 1;
for (long long k = 1; k <= 200; k++)
{
if (k > base)
{
power++;
base *= 2;
}
bound += power;
}
return bound;
}
void SolveWrongly()
{
ComputeBinaryExponentiation();
long long total_binary_count = 0;
for (long long k = 1; k <= 200; k++)
{
total_binary_count += GetBinaryCount(k);
}
std::cout << total_binary_count << std::endl;
}
int main()
{
SolveWrongly();
return 0;
}
2013年8月14日 星期三
ProjectEuler 122 -- Binary method (WA)
訂閱:
張貼留言 (Atom)
答案落在 (1345, 1688) open interval 中間
回覆刪除http://wstein.org/ent/ent.pdf 數論講義
回覆刪除