이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uid uniform_int_distribution
#define uint unsigned int
#define ld long double
#define ll long long
#define ar array
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rint(l, r) uid<int>(l, r)(rng)
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.f); cerr << ','; __print(x.s); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
const int mod = 1e9+7;
void fadd(ll &a, ll &b) {
a += b;
if (a >= mod) a -= mod;
}
void test_case() {
int a, l; cin >> a >> l;
vector<int> t(a);
for (int &x : t) cin >> x;
vector<vector<vector<ll>>> dp(1<<a, vector<vector<ll>>(a+1, vector<ll>(l+1)));
dp[0][a][0] = 1;
for (int m = 0; m < 1<<a; m++) {
for (int i = 0; i <= a; i++) {
if (i != a && !((m>>i)&1)) continue;
for (int j = 0; j <= l; j++) {
if (!dp[m][i][j]) continue;
for (int k = 0; k < a; k++) {
if ((m>>k)&1) continue;
int new_weight = j + (i<a?abs(t[i]-t[k]):0);
if (new_weight <= l) {
fadd(dp[m|(1<<k)][k][new_weight], dp[m][i][j]);
}
}
}
}
}
ll ans = 0;
for (int i = 0; i < a; i++) {
for (int j = 0; j <= l; j++) {
fadd(ans, dp[(1<<a)-1][i][j]);
}
}
cout << ans << '\n';
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
// cin >> t;
while (t--) test_case();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |