-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af1b3fe
commit fc7969c
Showing
758 changed files
with
10,617 additions
and
398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
typedef long long ll; | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
int n; cin >> n; | ||
long double p[n + 1]; for (int i = 1; i <= n; i++) cin >> p[i]; | ||
|
||
int least = n / 2 + 1; | ||
long double dp[n + 1][least + 1]; | ||
for (int i = 0; i <= n; i++) for (int j = 0; j <= least; j++) { | ||
if (j == 0) dp[i][j] = 1; | ||
else if (i == 0) dp[i][j] = 0; | ||
else dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]); | ||
} | ||
|
||
cout << fixed << setprecision(10) << dp[n][least]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define int long long | ||
|
||
int n, a[3005]; | ||
int dp[3005][3005][2]; | ||
|
||
int solve(int l, int r, int player) { | ||
if (l == r) return (player == 0 ? a[l] : -a[l]); | ||
if (dp[l][r][player] != -1) return dp[l][r][player]; | ||
int val = 0; | ||
if (player == 0) { | ||
val = max(solve(l, r - 1, 1) + a[r], solve(l + 1, r, 1) + a[l]); | ||
} else { | ||
val = min(solve(l, r - 1, 0) - a[r], solve(l + 1, r, 0) - a[l]); | ||
} | ||
dp[l][r][player] = val; | ||
return val; | ||
} | ||
|
||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
cin >> n; | ||
for (int i = 0; i < n; i++) cin >> a[i]; | ||
for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j][0] = dp[i][j][1] = -1; | ||
cout << solve(0, n - 1, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
typedef long long ll; | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
int n; cin >> n; | ||
int a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; | ||
int dp[n + 1]; dp[0] = 0; dp[1] = 0; dp[2] = abs(a[2] - a[1]); | ||
for (int i = 3; i <= n; i++) | ||
dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2])); | ||
cout << dp[n]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
typedef long long ll; | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
int n, k; cin >> n >> k; | ||
int a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; | ||
int dp[n + 1]; dp[0] = 0; dp[1] = 0; | ||
for (int i = 2; i <= n; i++) { | ||
dp[i] = 1e9; | ||
for (int j = 1; j <= k; j++) { | ||
if (i > j) dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j])); | ||
} | ||
} | ||
cout << dp[n]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define int long long | ||
const int m = 1e9 + 7; | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
int h, w; cin >> h >> w; | ||
bool g[h + 1][w + 1]; | ||
for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) { | ||
char ch; cin >> ch; | ||
g[i][j] = ch == '#'; | ||
} | ||
|
||
int dp[h + 1][w + 1]; | ||
for (int i = 0; i <= h; i++) for (int j = 0; j <= w; j++) dp[i][j] = 0; | ||
dp[1][1] = 1; | ||
for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) { | ||
if (g[i][j]) { dp[i][j] = 0; continue; } | ||
if (i > 1) dp[i][j] = (dp[i][j] + dp[i - 1][j]) % m; | ||
if (j > 1) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % m; | ||
} | ||
|
||
cout << dp[h][w]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define int long long | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
int n, w; cin >> n >> w; | ||
int a[n + 1][2]; for (int i = 1; i <= n; i++) cin >> a[i][0] >> a[i][1]; | ||
int dp[n + 1][w + 1]; | ||
for (int i = 0; i <= n; i++) for (int j = 0; j <= w; j++) { | ||
if (i == 0 || j == 0) dp[i][j] = 0; | ||
else { | ||
dp[i][j] = dp[i - 1][j]; | ||
if (j >= a[i][0]) dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i][0]] + a[i][1]); | ||
} | ||
} | ||
cout << dp[n][w]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define int long long | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
int n, w; cin >> n >> w; | ||
int a[n + 1][2], sum = 0; | ||
for (int i = 1; i <= n; i++) { | ||
cin >> a[i][0] >> a[i][1]; | ||
sum += a[i][1]; | ||
} | ||
|
||
int dp[n + 1][sum + 1]; | ||
for (int i = 0; i <= n; i++) for (int j = 0; j <= sum; j++) { | ||
if (j == 0) dp[i][j] = 0; | ||
else if (i == 0) dp[i][j] = 1e9; | ||
else { | ||
dp[i][j] = dp[i - 1][j]; | ||
if (j >= a[i][1]) dp[i][j] = min(dp[i][j], dp[i - 1][j - a[i][1]] + a[i][0]); | ||
} | ||
} | ||
|
||
int ans = 0; | ||
for (int i = 0; i <= sum; i++) { | ||
if (dp[n][i] <= w) ans = max(ans, i); | ||
} | ||
|
||
cout << ans; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
typedef long long ll; | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
string a, b; cin >> a >> b; | ||
int n = a.size(), m = b.size(); | ||
int dp[n + 1][m + 1]; | ||
for (int i = 0; i <= n; i++) for (int j = 0; j <= m; j++) { | ||
if (i == 0 || j == 0) dp[i][j] = 0; | ||
else { | ||
if (a[i - 1] == b[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1; | ||
else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); | ||
} | ||
} | ||
|
||
string res = ""; | ||
while(n && m) { | ||
if(a[n - 1] == b[m - 1]) { | ||
res += a[n - 1]; | ||
n--; | ||
m--; | ||
} | ||
else if (dp[n - 1][m] > dp[n][m - 1]) n--; | ||
else m--; | ||
} | ||
|
||
reverse(res.begin(), res.end()); | ||
cout << res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
typedef long long ll; | ||
|
||
int n, m; | ||
int dp[100005]; | ||
vector<int> g[100005]; | ||
|
||
int dfs(int v) { | ||
if (dp[v] != 0) return dp[v]; | ||
for (const int &u : g[v]) { | ||
dp[u] = dfs(u); | ||
dp[v] = max(dp[v], dp[u] + 1); | ||
} | ||
return dp[v]; | ||
} | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
cin >> n >> m; | ||
for (int i = 0; i < m; i++) { | ||
int a, b; cin >> a >> b; a--; b--; | ||
g[a].push_back(b); | ||
} | ||
|
||
fill(dp, dp + n, 0); | ||
|
||
for (int i = 0; i < n; i++) dfs(i); | ||
|
||
cout << *max_element(dp, dp + n); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
typedef long long ll; | ||
|
||
int n; | ||
long double dp[301][301][301]; | ||
|
||
double memo(int x, int y, int z) { | ||
if(x < 0 || y < 0 || z < 0) return 0; | ||
if(x == 0 && y == 0 && z == 0) return 0; | ||
if(dp[x][y][z] > 0) return dp[x][y][z]; | ||
|
||
long double ret = n + x * memo(x - 1, y, z) // # 1 sushi | ||
+ y * memo(x + 1, y - 1, z) // # 2 sushi | ||
+ z * memo(x, y + 1, z - 1); // # 3 sushi | ||
|
||
return dp[x][y][z] = ret / (x + y + z); | ||
} | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
cin >> n; | ||
vector<int> a(n); for(int i = 0; i < n; ++i) cin >> a[i]; | ||
|
||
vector<int> freq(3); | ||
for(int x : a) freq[x - 1]++; | ||
|
||
memset(dp, -1, sizeof dp); | ||
|
||
cout << fixed << setprecision(10) << memo(freq[0], freq[1], freq[2]) << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
typedef long long ll; | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
int n; cin >> n; | ||
int a[n + 1][3]; for (int i = 1; i <= n; i++) cin >> a[i][0] >> a[i][1] >> a[i][2]; | ||
int dp[n + 1][3]; dp[0][0] = dp[0][1] = dp[0][2] = 0; | ||
for (int i = 1; i <= n; i++) { | ||
dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i][0]; | ||
dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + a[i][1]; | ||
dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + a[i][2]; | ||
} | ||
cout << max(max(dp[n][0], dp[n][1]), dp[n][2]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
typedef long long ll; | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
int q; cin >> q; | ||
if (q == 1) { | ||
int n; cin >> n; | ||
cout << "Tarou wo Noriko wa mimashita"; | ||
} else if (q == 2) { | ||
int n; cin >> n; | ||
int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; | ||
sort(a, a + n); | ||
for (int i = 0; i < n; i++) cout << a[i] << ' '; | ||
} else if (q == 3) { | ||
cout << 69; | ||
} else cout << "toilet"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define int long long | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
int n; cin >> n; | ||
int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; | ||
for (int i = 0; i < n - 1; i++) { | ||
if (a[i] % 2 != 0) { | ||
cout << "NO"; | ||
return 0; | ||
} | ||
a[i + 1] += (a[i] / 2); | ||
a[i] = 0; | ||
} | ||
|
||
if (a[n - 1] % 2 == 0) cout << "YES"; | ||
else cout << "NO"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
typedef long long ll; | ||
|
||
int n, s = 0; | ||
pair<int, int> dp[1005][100005]; | ||
pair<int, int> a[1005]; | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
cin >> n; | ||
for (int i = 1; i <= n; i++) cin >> a[i].first, s += a[i].first; | ||
for (int i = 1; i <= n; i++) cin >> a[i].second; | ||
sort(a + 1, a + n + 1, [](pair<int, int> &u, pair<int, int> &v) { return u.second > v.second; }); | ||
|
||
int cur = 0, x = 0; | ||
while (cur < s) x++, cur += a[x].second; | ||
|
||
memset(dp, 128, sizeof(dp)); | ||
for (int i = 0; i <= n; i++) dp[i][0] = make_pair(0, 0); | ||
for (int i = 1; i <= n; i++) for (int k = cur; k >= a[i].second; k--) { | ||
dp[i][k] = max(dp[i-1][k], make_pair(dp[i-1][k-a[i].second].first - 1, | ||
dp[i-1][k-a[i].second].second + a[i].first)); | ||
} | ||
|
||
int mx = 0; | ||
for (int i = s; i <= cur; i++) if (dp[n][i].first == -x) mx = max(mx, dp[n][i].second); | ||
cout << x << ' ' << s - mx; | ||
} |
Oops, something went wrong.