2018-02-23考试

题目

结果

题解

T1

Tarjian判环板子题…

T2

较简单的DP $f(i,\;j)=f(i-j,\;j)+f(i-1,\;j-1)$

T3

最大子矩阵板子题

代码

T1

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
#include<bits/stdc++.h>
#define RG register
#define file(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout);
#define for_edge(i, x) for(RG int i=head[x];i;i=e[i].next)
#define clear(x, y) memset(x, y, sizeof(x));
using namespace std;

inline int read()
{
int data=0, w=1;
char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
if(ch=='-') w=-1, ch=getchar();
while(ch>='0'&&ch<='9') data=(data<<3)+(data<<1)+(ch^48), ch=getchar();
return data*w;
}

#define yes "Yes"
#define no "No"
const int maxn(2e4+10), maxm(1e5+10);
struct edge { int next, to; } e[maxm];
int head[maxn], e_num, T, n, m, a, b, dfn[maxn], low[maxn], stk[maxn], top, cnt;
bool tag, vis[maxn];
inline void add_edge(int from, int to) { e[++e_num]=(edge){head[from], to}; head[from]=e_num; }

inline void pop(int u)
{
int x=0;
while(stk[top]!=u) vis[stk[top]]=false, top--, x++;
vis[stk[top]]=false; top--; x++;
if(x>1) tag=true;
}

inline void Tarjian(int x)
{
low[x]=dfn[x]=++cnt; stk[++top]=x; vis[x]=true;
for_edge(i, x)
{
int to=e[i].to;
if(!dfn[to])
{
Tarjian(to);
low[x]=min(low[x], low[to]);
}
else if(vis[to]) low[x]=min(low[x], dfn[to]);
}
if(dfn[x]==low[x]) pop(x);
}

int main()
{
T=read();
while(T--)
{
clear(head, 0); e_num=0; clear(dfn, 0); clear(low, 0);
n=read(); m=read(); tag=false; cnt=0;
for(RG int i=1;i<=m;i++) { a=read(); b=read(); add_edge(a, b); }
for(RG int i=1;i<=n;i++) if(!dfn[i]) Tarjian(i);
if(tag) puts(no);
else puts(yes);
}
return 0;
}

T2

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
#include<bits/stdc++.h>
#define RG register
#define file(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout);
#define clear(x, y) memset(x, y, sizeof(x));
using namespace std;

inline int read()
{
int data=0, w=1;
char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
if(ch=='-') w=-1, ch=getchar();
while(ch>='0'&&ch<='9') data=(data<<3)+(data<<1)+(ch^48), ch=getchar();
return data*w;
}

const int mod(19940714), maxn(2010);
int n, m, f[maxn][maxn], ans;

int main()
{
n=read(); m=read();
f[0][0]=1; m=min(m, n);
for(RG int i=1;i<=n;i++)
for(RG int j=1;j<=min(m, i);j++)
f[i][j]=(f[i-j][j]+f[i-1][j-1])%mod;
for(RG int i=1;i<=m;i++) ans=(ans+f[n][i])%mod;
printf("%d\n", ans);
return 0;
}

T3

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
#include<bits/stdc++.h>
#define RG register
#define file(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout);
#define clear(x, y) memset(x, y, sizeof(x));
using namespace std;

inline int read()
{
int data=0, w=1;
char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
if(ch=='-') w=-1, ch=getchar();
while(ch>='0'&&ch<='9') data=(data<<3)+(data<<1)+(ch^48), ch=getchar();
return data*w;
}

#define int long long
const int maxn(310);
int g[maxn][maxn], n, m, a, b, c, f[maxn], ans;

main()
{
n=read(); m=read();
for(RG int i=1;i<=m;i++) a=read(), b=read(), c=read(), g[a][b]+=c;
for(RG int i=1;i<=n;i++) for(RG int j=1;j<=n;j++) g[i][j]+=g[i][j-1];
for(RG int i=1;i<=n;i++)
for(RG int j=i;j<=n;j++)
{
RG int s=0;
for(RG int k=1;k<=n;k++)
{
s+=g[k][j]-g[k][i-1];
if(s<0) s=0;
ans=max(ans, s);
}
}
printf("%lld\n", ans);
return 0;
}

总结 :

第三题 最大子矩阵不会做,爆凌了 只有200分
HYJ大佬290(Orz) 我还是太弱辣!

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×