A problem a day keeps WA away

自闭

KUANGBIN1简单搜索

注意搜索的范围

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
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define inc(i, l, r) for(int i=l; i<=r; i++)
const int inf = 0x3f3f3f3f;
const int maxn = 10;
int n, k;
char mp[maxn][maxn];
int ans = 0;
bool vis[maxn];
void dfs(int row, int tot){
if(row<=n&&tot == k){
ans++;
return;
}
else if(row>n||tot>k) return;
for(int i=row; i<n; i++){
for(int j=0; j<n; j++){
if(mp[i][j] == '.') continue;
if(vis[j]) continue;
vis[j] = true;
dfs(i+1, tot+1);//这边是i+1,否则会T
vis[j] = false;
}
}
}
int main(){
while(~scanf("%d%d", &n, &k)){
if(n == -1) break;
ans = 0;
getchar();
cls(vis, 0);
for(int i=0; i<n; i++) scanf("%s", mp[i]);
//for(int i=0; i<n; i++) printf("%s\n", mp[i]);
dfs(0, 0);
printf("%d\n", ans);
getchar();
}
}

TYVJ 1402 线性dp

没啥坑,注意乌龟初始在位置1,直接有一个贡献。

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
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define inc(i, l, r) for(int i=l; i<=r; i++)
const int inf = 0x3f3f3f3f;
const int maxn = 120+10;
int dp[45][45][45][45];
int value[500];
int n, m;
int card[maxn];
int dfs(int a, int b, int c, int d){
if(a+b+c+d == 0) return dp[a][b][c][d] = value[1];
if(dp[a][b][c][d]>0) return dp[a][b][c][d];
int now = a+2*b+3*c+4*d+1;
int val = value[now];
if(a>=1) dp[a][b][c][d] = max(dfs(a-1, b, c, d)+val, dp[a][b][c][d]);
if(b>=1) dp[a][b][c][d] = max(dfs(a, b-1, c, d)+val, dp[a][b][c][d]);
if(c>=1) dp[a][b][c][d] = max(dfs(a, b, c-1, d)+val, dp[a][b][c][d]);
if(d>=1) dp[a][b][c][d] = max(dfs(a, b, c, d-1)+val, dp[a][b][c][d]);
return dp[a][b][c][d];
}
int main(){
while(~scanf("%d%d", &n,&m)){
cls(card, 0);
cls(dp, 0);
cls(value, 0);
for(int i=1; i<=n; i++) scanf("%d", &value[i]);
for(int i=1; i<=m; i++){
int temp;
scanf("%d", &temp);
card[temp]++;
}
dfs(card[1], card[2], card[3], card[4]);
//cout<<dp[1][0][0][0]<<" "<<dp[0][1][0][0]<<endl;
//cout<<dp[1][1][0][0]<<endl;
printf("%d\n", dp[card[1]][card[2]][card[3]][card[4]]);
}
}

poj1187 括号的方案数统计

注意数据的范围,最后一组的维数是30,我wa了一万年。。。

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
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define inc(i, l, r) for(int i=l; i<=r; i++)
const int inf = 0x3f3f3f3f;
const int maxn = 20;
int l1, l2, l3, d;
const int mod = 11380;
int dp[maxn][maxn][maxn][40];
int dfs(int a, int b, int c, int depth){
if((dp[a][b][c][depth])>=0) return dp[a][b][c][depth];
if(a+b+c == 0) return dp[a][b][c][depth] = 1;
if(depth == 0) return dp[a][b][c][depth] = 0;
int ans = 0;
//cout<<a<<" "<<b<<" "<<c<<endl;
for(int i=0; i<=c; i++){//out braket is '()'
if(i) ans += dfs(0, 0, i-1, depth-1)*dfs(a, b, c-i, depth)%mod, ans%=mod;
for(int j=0; j<=b; j++){
if(j) ans += dfs(0, j-1, i, depth-1)*dfs(a, b-j, c-i, depth)%mod, ans%=mod;
for(int k=1; k<=a; k++){
ans += dfs(k-1, j, i, depth-1)*dfs(a-k, b-j, c-i, depth)%mod;
ans %= mod;
}
}
}
return dp[a][b][c][depth] = ans;
}
int main(){
while(~scanf("%d%d%d%d", &l1, &l2, &l3, &d)){
cls(dp, -1);
int ans1 = dfs(l1, l2, l3, d);
if(d!=0) dfs(l1, l2, l3, d-1);
int ans2;
if(d == 0) ans2 = 0;
else ans2 = dp[l1][l2][l3][d-1];
printf("%d\n", ((ans1-ans2)%mod+mod)%mod);
}
}

未解决的问题

文章目录
  1. 1. KUANGBIN1简单搜索
  2. 2. TYVJ 1402 线性dp
  3. 3. poj1187 括号的方案数统计
  4. 4. 未解决的问题
{{ live2d() }}