LJC00118 @ 2018-08-19 08:39:18
rt
代码如下
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 22;
ll a[N], s[1 << N];
int n, len = 0; ll m, ans = 0;
void dfs1(int u, ll now) {
if(now > m) return;
if(u > (n - (n >> 1))) {
s[++len] = now;
return;
}
dfs1(u + 1, now);
dfs1(u + 1, now + a[u]);
}
void dfs2(int u, ll now) {
if(now > m) return;
if(u > n) {
int l = 1, r = len;
while(l < r) {
int mid = (l + r + 1) >> 1;
if(s[mid] + now <= m) l = mid;
else r = mid - 1;
}
ans += (ll)(l);
return;
}
dfs2(u + 1, now);
dfs2(u + 1, now + a[u]);
}
int main() {
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
if(n == 1) {
if(a[1] <= m) puts("2");
else puts("1");
return 0;
}
dfs1(1, 0ll);
sort(s + 1, s + len + 1);
dfs2(n - n / 2 + 1, 0ll);
cout << ans << endl;
return 0;
}
求dalao帮忙
by YT0104 @ 2023-03-17 16:03:59
@LJC00118 额(⊙﹏⊙)
(关于我开了(1<<20)的数组,过了…………
评测记录:https://www.luogu.com.cn/record/104959172
by YT0104 @ 2023-03-17 16:05:39
所以,数据是不是有亿点点的淼……
by CEFqwq @ 2024-06-06 20:59:13
做到 U 布置的这道题,前来考古。