#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 10;
struct node {
int k, p;
} a[N];
int n, m, ans, tot1 = 0, tot2 = 0;
map<int, int> mp1, mp2;
inline int pow(int a, int x) {
int s = 1, tmp = x;
while(x--) {
s *= a;
}
return s;
}
inline bool cmp(int x, int y) {
return x > y;
}
inline void dfs1(int x, int sum) {
if(x > n / 2) {
mp1[++tot1] = sum;
return ;
}
for(int i = 1; i <= m; i++) {
dfs1(x + 1, sum + a[x].k * pow(i, a[x].p));
}
}
inline void dfs2(int x, int sum) {
if(x > n) {
mp2[++tot2] = sum;
return ;
}
for(int i = 1; i <= m; i++) {
dfs2(x + 1, sum + a[x].k * pow(i, a[x].p));
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> a[i].k >> a[i].p;
}
dfs1(1, 0);
dfs2(n / 2 + 1, 0);
sort(mp1.begin(), mp1.end());
sort(mp2.begin(), mp2.end(), cmp);
for(int i = 1, j = tot2; i <= tot1 && j >= 1; ) {
int k = i, kk = j;
while(mp1[i] == mp1[k] && i <= tot1 + 1) {
++i;
}
while(mp2[j] == -mp1[k] && j >= 0) {
--j;
}
ans += ((i - k) * (kk - j));
}
cout << ans;
return 0;
}
评测记录