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 夜刀神十香ღ @ 2018-08-19 08:41:07
Orz前排大佬
by LJC00118 @ 2018-08-19 08:41:57
@sooke @按Ctrl加w会AC @yyfcpp
召唤各位dalao前来帮忙
by LJC00118 @ 2018-08-19 08:43:00
@夜刀神十香ღ 您才是 dalao 啊 QAQ
by 夜刀神十香ღ @ 2018-08-19 08:46:21
@LJC00118 才不是呢QAQ
by 夜刀神十香ღ @ 2018-08-19 08:47:30
@LJC00118 全改成long long有63分
https://www.luogu.org/recordnew/show/9904646
by LJC00118 @ 2018-08-19 08:48:30
问题已解决,我数组开小了
by LJC00118 @ 2018-08-19 08:49:01
感谢 @夜刀神十香ღ 的帮助qwq
by LJC00118 @ 2018-08-19 08:50:30
@夜刀神十香ღ
顺便说一下,您的代码里
by Planet6174 @ 2018-08-19 08:50:49
LOJ 上的是官方数据啊…… 难道洛谷上的是加强版?
by LJC00118 @ 2018-08-19 08:51:03
1 << 20 是不行的