DESCRIPTION

INPUT

OUTPUT

SAMPLE INPUT
1 3 3 0 0 0 1 1 1 1 1 1 1 2 3
SAMPLE OUTPUT
1 1 3
HINT

SOLUTION

 1 #pragma comment(linker, "/STACK:102400000,102400000")
2 #include <cstdio>
3 #include <iostream>
4 #include <cstdlib>
5 #include <cstring>
6 #include <algorithm>
7 #include <cmath>
8 #include <cctype>
9 #include <map>
10 #include <set>
11 #include <queue>
12 #include <bitset>
13 #include <string>
14 #include <complex>
15 #define ll long long
16 using namespace std;
17 int t;
18 int n,q;
19 int mp[15][15][15];
20 int x[50004],y[50004],z[50004];
21 int s[50004];
22 ll sum[505];
23 int main()
24 {
25     scanf("%d",&t);
26     for(int i=1;i<=t;i++)
27     {
28         for(int j=0;j<=10;j++)
29             for(int l=0;l<=10;l++)
30              for(int k=0;k<=10;k++)
31                mp[j][l][k]=0;
32         for(int j=0;j<=50;j++)
33             sum[j]=0;
34         scanf("%d %d",&n,&q);
35         int jishu=0;
36         for(int j=1;j<=n;j++)
37         {
38             scanf("%d %d %d",&x[j],&y[j],&z[j]);
39             if(mp[x[j]][y[j]][z[j]]==0)
40                 s[jishu++]=j;
41             mp[x[j]][y[j]][z[j]]++;
42       }
43         for(int j=0;j<jishu;j++)
44         {
45             for(int k=j;k<jishu;k++)
46             {
47                 if(j==k)
48                 {
49                     ll now=mp[x[s[j]]][y[s[j]]][z[s[j]]];
50                     sum[0]+=now*(now-1)/2;
51                 }
52                 else{
53  int dis=abs(x[s[j]]-x[s[k]])+abs(y[s[j]]-y[s[k]])+abs(z[s[j]]-z[s[k]]);
54   sum[dis]+=mp[x[s[k]]][y[s[k]]][z[s[k]]]*mp[x[s[j]]][y[s[j]]][z[s[j]]];
55                 }
56             }
57         }
58         for(int j=1;j<=50;j++)
59             sum[j]+=sum[j-1];
60         int exm;
61         for(int j=1;j<=q;j++)
62         {
63             scanf("%d",&exm);
64             if(exm>50)
65                 printf("%lld\n",sum[50]);
66             else
67                 printf("%lld\n",sum[exm]);
68         }
69     }
70     return 0;
71 }

DESCRIPTION

INPUT

OUTPUT

SAMPLE INPUT
2 3 2 3 5 7 3 10 3 5 7
SAMPLE OUTPUT
12 26
HINT

1.然后我们发现这个

2.我们也可以简单的推导一下发现这个

 1 #pragma comment(linker, "/STACK:102400000,102400000")
2 #include <cstdio>
3 #include <iostream>
4 #include <cstdlib>
5 #include <cstring>
6 #include <algorithm>
7 #include <cmath>
8 #include <cctype>
9 #include <map>
10 #include <set>
11 #include <queue>
12 #include <bitset>
13 #include <string>
14 #include <complex>
15 #define ll long long
16 using namespace std;
17 int t;
18 int aa[100005];
19 int b[100005];
20 ll dp[3000006];
21 map<int,int>mp;
22 int n,a;
23 int main()
24 {
25     scanf("%d",&t);
26     int ans=0;
27     for(int j=1;j<=t;j++)
28     {
29         scanf("%d %d",&n,&a);
30         int jishu=0;
31         mp.clear();
32         for(int i=1;i<=n;i++){
33             scanf("%d",&aa[i]);
34             if(mp[aa[i]]==0){
35                 b[jishu++]=aa[i];
36                 mp[aa[i]]=1;
37             }
38             }
39         sort(b,b+jishu);
40         for(int i=0;i<jishu;i++){
41             dp[i]=1e18+1;
42             }
43         dp[0]=0;
44         for(int i=1;i<jishu;i++)
45         {
46             for(int j=i-1;j>=0;j--)
47             {
48                 if(b[i]-b[j]>30)
49                     break;
50                 dp[i]=min(dp[i],dp[j]+(1ll<<(b[i]-b[j]))+a);
51             }
52         }
53         printf("%lld\n",dp[jishu-1]);
54     }
55     return 0;
56 }