Example #1
0
	int maxEnergy(vector <int> weight) {
		m.clear();
		memset(x, 0, sizeof(x));
		len = weight.size();
		if (len < 3) {
			return 0;
		}
		if (len == 3) {
			return weight[0]*weight[2];
		}
		int i;
		for (i = 0; i < len; ++i) {
			x[i] = weight[i];
		}
		int all_mask = (1<<len)-1;
		int mid_mask = ((1<<(len-2))-1)*2;
		int end_mask = all_mask ^ mid_mask;
		m[end_mask] = 0;
		return rec(all_mask);
	}
Example #2
0
void ListMapTest::testInsert()
{
    const int N = 1000;

    typedef ListMap<int, int> IntMap;
    IntMap hm;

    assert (hm.empty());

    for (int i = 0; i < N; ++i)
    {
        IntMap::Iterator res = hm.insert(IntMap::ValueType(i, i*2));
        assert (res->first == i);
        assert (res->second == i*2);
        IntMap::Iterator it = hm.find(i);
        assert (it != hm.end());
        assert (it->first == i);
        assert (it->second == i*2);
        assert (hm.size() == i + 1);
    }

    assert (!hm.empty());

    for (int i = 0; i < N; ++i)
    {
        IntMap::Iterator it = hm.find(i);
        assert (it != hm.end());
        assert (it->first == i);
        assert (it->second == i*2);
    }

    hm.clear();
    for (int i = 0; i < N; ++i)
    {
        IntMap::Iterator res = hm.insert(IntMap::ValueType(i, 0));
        assert (res->first == i);
        assert (res->second == 0);
    }
}