Skip to content

Commit be0db23

Browse files
committed
DP Hard (1)
1 parent d9e7548 commit be0db23

File tree

6 files changed

+95
-10
lines changed

6 files changed

+95
-10
lines changed

Algospot/MORSE.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
#include <string>
4+
5+
using namespace std;
6+
7+
typedef long long ll;
8+
9+
ll bino[202][202];
10+
int c, n, m, k;
11+
12+
ll binomial(int a, int b)
13+
{
14+
ll& ret = bino[a][b];
15+
16+
if(ret)
17+
return ret;
18+
else if(a == b || b == 0)
19+
return ret = 1;
20+
else
21+
return ret = binomial(a - 1, b - 1) + binomial(a - 1, b);
22+
}
23+
24+
void dp(int a, int b, int skip, string& ans)
25+
{
26+
ll left = binomial(a + b - 1, a - 1);
27+
// cout << ans << ' ' << skip << ' ' << left << '\n';
28+
if(a == 0 && b == 0)
29+
return;
30+
31+
if(a > 0 && skip <= left)
32+
{
33+
ans += '-';
34+
dp(a - 1, b, skip, ans);
35+
}
36+
else
37+
{
38+
ans += 'o';
39+
dp(a, b - 1, skip - left, ans);
40+
}
41+
}
42+
43+
int main()
44+
{
45+
for(cin >> c; c > 0; c--)
46+
{
47+
cin >> n >> m >> k;
48+
string ans = "";
49+
50+
dp(n, m, k, ans);
51+
cout << ans << '\n';
52+
}
53+
}

Algospot/a.out

-4.32 KB
Binary file not shown.

Algospot/input

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
4
2-
w
3-
xbwwb
4-
xbwxwbbwb
5-
xxwwwbxwxwbbbwwxxxwwbbbwwwwbb
1+
3
2+
2 2 4
3+
4 8 13
4+
100 100 1

baekjoon/12865.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
4+
using namespace std;
5+
6+
int n, v, w, k, ans;
7+
int cache[100002];
8+
9+
int main()
10+
{
11+
cin >> n >> k;
12+
for(int j = 1; j <= k; j++)
13+
cache[j] = -1;
14+
15+
for(int i = 1; i <= n; i++)
16+
{
17+
cin >> w >> v;
18+
19+
for(int j = k; j >= 0; j--)
20+
{
21+
int& here = cache[j];
22+
23+
if(j - w >= 0 && cache[j - w] != -1)
24+
{
25+
here = max(here, cache[j - w] + v);
26+
}
27+
28+
ans = max(ans, cache[j]);
29+
}
30+
}
31+
32+
cout << ans << '\n';
33+
}

baekjoon/a.out

-13.8 KB
Binary file not shown.

baekjoon/input

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
4
2-
0 0
3-
10 10
4-
0 10
5-
10 0
1+
4 7
2+
6 13
3+
4 8
4+
3 6
5+
5 12

0 commit comments

Comments
 (0)