제출 #1178766

#제출 시각아이디문제언어결과실행 시간메모리
1178766ericl23302Skyscraper (JOI16_skyscraper)C++20
20 / 100
469 ms186096 KiB
#include <iostream> #include <vector> #include <algorithm> #include <cstdlib> #include <map> #define int long long using namespace std; int n, l; vector<int> heights; vector<vector<vector<int>>> dp; int doDp(int bitmask, int last, int tot) { if (dp[bitmask][last][tot] != -1) return dp[bitmask][last][tot]; int prevBitmask = bitmask - (1 << last); dp[bitmask][last][tot] = 0; for (int i = 0; i < n; ++i) { if (!((1 << i) & prevBitmask) || tot < abs(heights[i] - heights[last])) continue; dp[bitmask][last][tot] += doDp(prevBitmask, i, tot - abs(heights[i] - heights[last])); dp[bitmask][last][tot] %= 1'000'000'007; } return dp[bitmask][last][tot]; } // vector<vector<vector<int>>> dp; // int doDp(int bitmask, int last, int tot, vector<int> &heights, int n, int l) { // if (dp[bitmask][last][tot] != -1) return dp[bitmask][last][tot]; // int prevBitmask = bitmask - (1 << last); // dp[bitmask][last][tot] = 0; // for (int i = 0; i < n; ++i) { // if (!((1 << i) & prevBitmask) || tot < abs(heights[i] - heights[last])) continue; // dp[bitmask][last][tot] += doDp(prevBitmask, i, tot - abs(heights[i] - heights[last]), heights, n, l); // dp[bitmask][last][tot] %= 1'000'000'009; // } // return dp[bitmask][last][tot]; // } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> l; heights.resize(n); for (int &i : heights) cin >> i; // sort(heights.begin(), heights.end()); dp.resize((1 << n), vector<vector<int>>(n, vector<int>(l + 1, -1))); for (int i = 0; i < n; ++i) { // for (int j = 1; j <= l; ++j) dp[(1 << i)][i][j] = 0; // dp[(1 << i)][i][0] = 1; for (int j = 0; j <= l; ++j) dp[(1 << i)][i][j] = 1; } int res = 0; for (int i = 0; i < n; ++i) { // for (int j = 0; j <= l; ++j) { // res += doDp((1 << n) - 1, i, j); // // cout << i << ' ' << j << ' ' << doDp((1 << n) - 1, i, j) << '\n'; // res %= 1'000'000'007; // } res += doDp((1 << n) - 1, i, l); res %= 1'000'000'007; } cout << res << '\n'; // auto code = [&](int n, int l, vector<int> &heights) { // dp.clear(); // dp.resize((1 << n), vector<vector<int>>(n, vector<int>(l + 1, -1))); // for (int i = 0; i < n; ++i) { // for (int j = 0; j <= l; ++j) dp[(1 << i)][i][j] = 1; // } // int res = 0; // for (int i = 0; i < n; ++i) { // res += doDp((1 << n) - 1, i, l, heights, n, l); // res %= 1'000'000'007; // } // return res; // }; // auto checker = [&](int n, int l, vector<int> &heights) { // int res = 0; // sort(heights.begin(), heights.end()); // do { // int tot = 0; // for (int i = 0; i < n - 1; ++i) tot += abs(heights[i] - heights[i + 1]); // res += (tot <= l); // res %= 1'000'000'007; // } while (next_permutation(heights.begin(), heights.end())); // return res; // }; // srand(time({})); // int n = 8; // bool error = false; // for (int i = 0; i < 200; ++i) { // vector<int> heights; // map<int, bool> inHeights; // while (heights.size() < n) { // int val = rand() % 100 + 1; // if (!inHeights[val]) heights.push_back(val), inHeights[val] = true; // } // for (int j = 0; j <= 100; ++j) { // int codeRes = code(n, j, heights); // int checkerRes = checker(n, j, heights); // if (codeRes != checkerRes) { // cout << "Bug detected\nheights: "; // for (int &i : heights) cout << i << ' '; // cout << '\n'; // cout << "l: " << j << '\n'; // cout << "Code gives: " << codeRes << '\n'; // cout << "Checker gives: " << checkerRes << '\n'; // error = true; // break; // } // } // if (error) break; // cout << "Test " << i + 1 << " done with no errors\n"; // cout << "heights: "; // for (int &i : heights) cout << i << ' '; // cout << '\n'; // } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...