Skip to content

Commit

Permalink
apt coder
Browse files Browse the repository at this point in the history
  • Loading branch information
npjd committed Feb 16, 2025
1 parent 77339c3 commit 37eea19
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file added USACO/.DS_Store
Binary file not shown.
Binary file added atcoder-dp-contest/a.out
Binary file not shown.
40 changes: 40 additions & 0 deletions atcoder-dp-contest/grid1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
int H, W;
cin >> H >> W;

vector<vector<int> > dp(H + 1, vector<int>(W + 1, 0));


string row;

for (int i = 1; i < H + 1; i++)
{
cin >> row;

for (int j = 1; j < W + 1; j++)
{
if (i == 1 && j ==1)
{
dp[i][j] = 1;
continue;
}

if (row[j - 1] == '#')
{
continue;
}

dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]);
dp[i][j] %= (int)(1e9 +7);
}
}

cout << dp[H][W] << endl;
}
58 changes: 58 additions & 0 deletions atcoder-dp-contest/lcs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){

string s, t;

cin >> s;
cin >> t;

int n = s.length();
int m = t.length();

vector<vector<int> > dp(n+1, vector<int>(m+1, 0));

for (int i = 1; i < n+1; i++)
{
for (int j = 1; j < m+1; j++)
{
if (s[i-1] == t[j-1])
{
dp[i][j] = 1 + dp[i-1][j-1];
}
else{
dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
}
}
}

int i = n, j = m;
string lcs = "";


while (i > 0 && j > 0)
{
if (s[i-1] == t[j-1])
{
lcs += s[i-1];
i -= 1;
j -= 1;
}
else if(dp[i-1][j] >= dp[i][j-1]){
i -= 1;
}
else{
j -=1 ;
}
}

reverse(lcs.begin(), lcs.end());

cout << lcs << endl;

}
62 changes: 62 additions & 0 deletions atcoder-dp-contest/longest_path.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

#include <vector>
#include <iostream>

using namespace std;

void dfs(int i, vector<int> &dp, vector<bool> & vis, vector<vector<int> > &adj)
{
vis[i] = true;

int ans = 0;

for (int j = 0; j < adj[i].size(); j++)
{
int nei = adj[i][j];
if (!vis[nei])
{
dfs(nei, dp, vis, adj);
}
ans = max(ans, 1 + dp[nei]);
}

dp[i] = ans;
}

int main()
{
int N, M;
cin >> N >> M;

vector<int> dp(N + 1, 0);

vector<vector<int> > adj(N + 1, vector<int>(0));

vector<bool> vis(N + 1, false);

int x, y;

for (int i = 0; i < M; i++)
{

cin >> x >> y;
adj[x].push_back(y);
}

for (int i = 1; i <= N; i++)
{
if (!vis[i])
{
dfs(i, dp, vis, adj);
}
}

int ans = 0;

for (int i = 1; i <= N; i++)
{
ans = max(ans, dp[i]);
}

cout << ans << endl;
}

0 comments on commit 37eea19

Please sign in to comment.