用bitset位操作代替逐个询问

已存在,只需 存在,就有 存在

而题意只需要价值存在即可

利用鬼谷子的钱包的分治思想优化解法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <cstdio>
#include <bitset>
using namespace std;

const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;

#define f(i, a, b) for (int i = a; i <= b; i++)
#define LL long long
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define scan(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define sqr(x) (x) * (x)
#define pr1(x) printf("Case %d: ", x)
#define pn1(x) printf("Case %d:\n", x)
#define pr2(x) printf("Case #%d: ", x)
#define pn2(x) printf("Case #%d:\n", x)
#define lowbit(x) (x & (-x))

typedef unsigned long long ull;

struct FastIO
{
static const int S = 5 << 20; //MB
int wpos;
char wbuf[S];
FastIO() : wpos(0) {}
inline int xchar()
{
static char buf[S];
static int len = 0, pos = 0;
if (pos == len)
pos = 0, len = fread(buf, 1, S, stdin);
if (pos == len)
return -1;
return buf[pos++];
}
inline int xuint()
{
int c = xchar(), x = 0;
while (~c && c <= 32)
c = xchar();
for (; '0' <= c && c <= '9'; c = xchar())
x = x * 10 + c - '0';
return x;
}
inline LL xull()
{
int c = xchar();
LL x = 0;
while (~c && c <= 32)
c = xchar();
for (; '0' <= c && c <= '9'; c = xchar())
x = x * 10 + c - '0';
return x;
}
inline int xint()
{
int s = 1, c = xchar(), x = 0;
while (c <= 32)
c = xchar();
if (c == '-')
s = -1, c = xchar();
for (; '0' <= c && c <= '9'; c = xchar())
x = x * 10 + c - '0';
return x * s;
}
inline void xstring(char *s)
{
int c = xchar();
while (c <= 32)
c = xchar();
for (; c > 32; c = xchar())
*s++ = c;
*s = 0;
}
inline void wchar(int x)
{
if (wpos == S)
fwrite(wbuf, 1, S, stdout), wpos = 0;
wbuf[wpos++] = x;
}
inline void wll(LL x)
{
if (x < 0)
wchar('-'), x = -x;

char s[30];
int n = 0;
while (x || !n)
s[n++] = '0' + x % 10, x /= 10;
while (n--)
wchar(s[n]);
}
inline void wstring(const char *s)
{
while (*s)
wchar(*s++);
}
~FastIO()
{
if (wpos)
fwrite(wbuf, 1, wpos, stdout), wpos = 0;
}
} io;

LL s, sum, a[7], cnt;
bitset<20000> dp;

int main()
{
//IN;
// OUT;
while (++cnt)
{
s = 0;
dp.reset();
dp.set(0);
f(i, 1, 6)
s += (a[i] = io.xint()) * i;
//io.wll(s);
if (s == 0)
break;
io.wstring("Collection #");
io.wll(cnt);
io.wchar(':');
io.wchar('\n');
if (s & 1)
io.wstring("Can't be divided.\n\n");
else
{
s >>= 1;
f(i, 1, 6)
{
for (int j = a[i]; j > 0; j >>= 1)
{
int k = ((j + 1) >> 1) * i;
dp |= (dp << k);
if (dp[s])
{
break;
}
}
if (dp[s])
break;
}
if (dp[s])
io.wstring("Can be divided.\n\n");
else
io.wstring("Can't be divided.\n\n");
}
}
}

看了题解要分治,一开始打的代码有bug还不清楚什么情况

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <cstdio>
#include <algorithm>
using namespace std;

const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;

#define f(i, a, b) for (int i = a; i <= b; i++)
#define LL long long
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define scan(x) scanf("%lld", &x)
#define mp make_pair
#define pb push_back
#define sqr(x) (x) * (x)
#define pr1(x) printf("Case %d: ", x)
#define pn1(x) printf("Case %d:\n", x)
#define pr2(x) printf("Case #%d: ", x)
#define pn2(x) printf("Case #%d:\n", x)
#define lowbit(x) (x & (-x))

typedef unsigned long long ull;
const LL N = 1e4 + 1;
LL m, a[N], cnt;

int main()
{
scan(m);
while(m>0){
a[cnt++]=(m+1)>>1;
m>>=1;
}
sort(a,a+cnt);
printf("%lld\n",cnt);
f(i,0,cnt-1)printf("%lld ",a[i]);
return 0;
}

今天是大佬带我躺,没想到英语老毛病又犯了height以为是重量

回来时还书不会还,回宿舍路上还撞路灯,脸上开花。。。

不过中午提供的免费盒饭和牛奶倒是可以


一开始想切L,但想法总是有误,欧拉函数没学。。。

G竟然是泰勒,但好像洛必达也能做,还是太菜了

今天感觉唯一帮助就是个双目三目运算符,。。。。。。

该肝了


感谢队友不杀之恩!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<bits/stdc++.h>
#define scan(x) scanf("%lld",&x)
#define f(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef long long LL;
const LL N=186;
LL dp[N][N],data[N][N],r,c,maxn;
LL dyp(LL i,LL j) {
if(dp[i][j]!=-1) return dp[i][j];
LL a[4]= {1,1,1,1};
if(i-1>0&&data[i-1][j]<data[i][j]) {
a[0]+=dyp(i-1,j);
}
if(i+1<=r&&data[i+1][j]<data[i][j]) {
a[1]+=dyp(i+1,j);
}
if(j-1>0&&data[i][j-1]<data[i][j]) {
a[2]+=dyp(i,j-1);
}
if(j+1<=c&&data[i][j+1]<data[i][j]) {
a[3]+=dyp(i,j+1);
}
sort(a,a+4);
dp[i][j]=a[3];
return a[3];
}

int main() {
scan(r);
scan(c);
f(i,1,r) {
f(j,1,c) {
scan(data[i][j]);
dp[i][j]=-1;
}
}
f(i,1,r) {
f(j,1,c) {
maxn=maxn<dyp(i,j)?dyp(i,j):maxn;
}
}

printf("%lld",maxn);
return 0;
}

有一个样例是全为0三角形,而一开始dp数组未初始化为特殊值仅特判是否为0,从而导致TLE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <cstdio>
#define scan(x) scanf("%lld",&x)
#define f(i,a,b) for(int i=a;i<=b;i++)
#define pn(x,y) printf("###%lld:::%lld\n",x,y)
using namespace std;
typedef long long LL;
const LL N=1e3+1;
LL a[N][N],r,f[N][N];

struct FastIO {
static const int S = 5 << 20; //MB
int wpos; char wbuf[S];
FastIO() : wpos(0) {}
inline int xchar() {
static char buf[S];
static int len = 0, pos = 0;
if(pos == len)
pos = 0, len = fread(buf, 1, S, stdin);
if(pos == len) return -1;
return buf[pos ++];
}
inline int xuint() {
int c = xchar(), x = 0;
while(~c && c <= 32) c = xchar();
for(; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0';
return x;
}
inline LL xull() {
int c = xchar();
LL x = 0;
while(~c && c <= 32) c = xchar();
for(; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0';
return x;
}
inline int xint() {
int s = 1, c = xchar(), x = 0;
while(c <= 32) c = xchar();
if(c == '-') s = -1, c = xchar();
for(; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0';
return x * s;
}
inline void xstring(char* s) {
int c = xchar();
while(c <= 32) c = xchar();
for(; c > 32; c = xchar()) * s++ = c;
*s = 0;
}
inline void wchar(int x) {
if(wpos == S) fwrite(wbuf, 1, S, stdout), wpos = 0;
wbuf[wpos ++] = x;
}
inline void wll(LL x) {
if(x < 0) wchar('-'), x = -x;

char s[30];
int n = 0;
while(x || !n) s[n ++] = '0' + x % 10, x /= 10;
while(n--) wchar(s[n]);
}
inline void wstring(const char* s) {
while(*s) wchar(*s++);
}
~FastIO() {
if(wpos) fwrite(wbuf, 1, wpos, stdout), wpos = 0;
}
} io;

LL dyp(LL i,LL j) {
if(i==r)return a[i-1][j];
if(f[i][j]!=-1)return f[i][j];
LL q=a[i-1][j]+(dyp(i+1,j)<dyp(i+1,j+1)?dyp(i+1,j+1):dyp(i+1,j));
f[i][j]=q;
return q;
}
int main() {
r=io.xint();
f(i,1,r) {
f(j,1,i) {
a[i-1][j-1]=io.xint();
f[i][j-1]=-1;
}
}
io.wll(dyp(1,0));
return 0;
}
0%