POJ 不支持 unordered_map
需要自己写hash函数 用开放地址法处理冲突 就是找到后面的第一个空位
math.h pow有精度问题 自己写一个快速幂

一共n个数 全部放在一边计算肯定超时,两边各分n/2个 这样复杂度就下来了(移项记得加负号)
当ki为0的时候不需要计算,可以进行剪枝

综上 这个题想一次通过还是有困难的
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <cstring>
#include <queue>
#include <map>
//#include <unordered_map>
#include <set>
//#include <unordered_set>
#include <stack>
#include <math.h>
#include <limits.h>
#include <stdio.h>
#include <vector>
#include <bitset>
#include <deque>
#include <functional>
#include <ctype.h>
#include <sstream>

using namespace std;
#pragma warning(disable:4996)

const double eps = 1e-6;
typedef long long ll;
#define debug(x) cout<<#x<<": "<<(x)<<endl;
#define lfeq(a,b) (abs((a)-(b)) < eps)

int mod = 10000007;
int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);

template <typename T> void inline read(T& x) {
int f = 1; x = 0; char s = getchar();
while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
x *= f;
}

template <typename T> void print(T x) {
if (x < 0) { putchar('-'); print(x); return; }
if (x >= 10) print(x / 10);
putchar((x % 10) + '0');
}

int lk[6];
int rk[6];
int lcnt = 0;
int rcnt = 0;
int lp[6];
int rp[6];
int n;
int m;

struct node {
int v;
int c;
node(): v(-1),c(0){}
}arr[10000010];

int myhash(int x) {
int i = ( (x%mod)+mod)%mod;
while ( arr[i].c>0 && arr[i].v != x) {
i = (i+1)%mod;
}
return i;
}

int Pow(int u, int k) {
int ret = 1, tmp = u;
while (k) {
if (k & 1)
ret *= tmp;
tmp *= tmp;
k >>= 1;
}
return ret;
}

bool cal(int sum,int index) {
if (index == lcnt) {
int h = myhash(sum);
arr[h].v = sum;
++arr[h].c;
return true;
}

if (lk[index] == 0) {
cal(sum, index + 1);
}
else {
for (float x = 1; x <= m; ++x) {

cal(sum + lk[index] * Pow(x, lp[index]), index + 1);
}
}
return true;
}

int cnt = 0;

bool calr(int sum,int index) {
if (index == rcnt) {
int h = myhash(sum);
cnt += arr[h].c;
return true;
}
if (rk[index] == 0) {
calr(sum , index + 1);
}
else {
for (float x = 1; x <= m; ++x) {
calr(sum + rk[index] * Pow(x, rp[index]), index + 1);
}
}

return true;
}

int main() {

//freopen("../in1.txt", "r", stdin);

read(n);

cin >> m;

for (int i = 0; i < n; ++i) {
int k;
int p;
read(k);
read(p);
if (i < n/2) {
lp[lcnt] = p;
lk[lcnt++] = k;
}
else {
rp[rcnt] = p;
rk[rcnt++] = -k;
}
}

cal(0,0);
calr(0,0);
cout << cnt << endl;
return 0;
}

POJ 1186 方程的解数【math.h pow有精度问题,自定义hash函数】_#define