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:51:10
@LJC00118 hmmm我都还没看题呢
by LJC00118 @ 2018-08-19 08:51:36
只能说明 loj 数据水,
by LJC00118 @ 2018-08-19 08:53:20
貌似 loj 数据也是 40 级别的,可能因为内存连续,我的
by LJC00118 @ 2018-08-19 08:53:42
是
by 夜刀神十香ღ @ 2018-08-19 08:55:52
@LJC00118 您TQL!%%%
by LJC00118 @ 2018-08-19 08:56:10
luogu 第四代评测机果然有很大的不同,loj AC 但是 luogu WA
by Planet6174 @ 2018-08-19 08:56:22
@LJC00118
唔
我今晚修一下
by LJC00118 @ 2018-08-19 08:57:18
@Planet6174 还是我自己的锅,应该不用修了吧
by Planet6174 @ 2018-08-19 09:14:10
@LJC00118 我们要保证有错的程序被卡掉
by Aleph1022 @ 2018-08-19 11:04:04
@Planet6174 不是吧……怕是CZ配置错了
话说Loj的评测姬确实很神奇,莫队忘记打排序居然只TLE掉三个点