pizzasoltu
quoc14
c_cpp
a year ago
1.5 kB
12
Indexable
caidat
#include <iostream>
using namespace std;
int k, nbar, mdd, r;
int maxans;
struct point{
int x;
int y;
};
struct bar{
int x;
int y;
int people;
};
point locations[104];
int kt[1002];
bar bars[104];
int abss(int aa)
{
return aa < 0 ? -aa : aa;
}
int khoangcach(point ll, bar bb)
{
int xx = abss(ll.x - bb.x);
int yy = abss(ll.y - bb.y);
if (xx*xx + yy*yy <= r*r)
return 1;
else return 0;
}
int chose(int j)
{
int tmp = 0;
for (int i = 1; i<=nbar; i++)
if (khoangcach(locations[j], bars[i]))
{
kt[i] += 1;
if (kt[i] == 1) tmp += bars[i].people;
}
return tmp;
}
void unchose(int j)
{
int tmp = 0;
for (int i = 1; i<=nbar; i++)
if (khoangcach(locations[j], bars[i]))
{
kt[i] -= 1;
}
}
void backtrack(int index, int i, int score)
{
for (int j = i; j <= mdd - k + index; j++)
{
int tmpp = chose(j) + score;
if (index < k)
{
backtrack(index + 1, j+1, tmpp);
} else if (index == k)
{
if (maxans < tmpp) maxans = tmpp;
}
unchose(j);
}
}
int main()
{
//freopen("input.txt","r",stdin);
int ntc;
cin >> ntc;
for (int tc=1; tc<=ntc; tc++)
{
cin >> k >> r;
cin >> mdd;
for (int i = 1; i<=mdd; i++)
cin >>locations[i].x >> locations[i].y;
cin >> nbar;
for (int i = 1; i<=nbar; i++)
cin >> bars[i].x >> bars[i].y >> bars[i].people;
maxans = 0;
backtrack(1,1, 0);
cout <<"#"<<tc <<" " << maxans << endl;
}
return 0;
}
Editor is loading...
Leave a Comment