saikizentansaku
abc165 c
int n, m, q;
int a[55], b[55], c[55], d[55];
int ans = 0;
void dfs(vector<int>&v) {
if (v.size() == n) {
int s = 0;
for (int i = 0; i < q; ++i) {
if (v[b[i]] - v[a[i]] == c[i])s += d[i];
}
ans = max(ans, s);
return;
}
int t = 1;
if (!v.empty())t = v.back();
for (int i = t; i <= m; ++i) {
v.push_back(i);
dfs(v);
v.pop_back();
}
}
int main() {
cin >> n >> m >> q;
for (int i = 0; i < q; ++i) {
cin >> a[i] >> b[i] >> c[i] >> d[i];
a[i]--, b[i]--;
}
vector<int>v;
dfs(v);
cout << ans << endl;
return 0;
}
ex 755,lunlunnumber,string equivalence
Author And Source
この問題について(saikizentansaku), 我々は、より多くの情報をここで見つけました https://qiita.com/bestfitat/items/ce02716f833bc02df27a著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .