Skip to content

Commit

Permalink
dp
Browse files Browse the repository at this point in the history
  • Loading branch information
gzshawnliang committed Feb 7, 2019
1 parent 0f31bab commit f60bb51
Show file tree
Hide file tree
Showing 30 changed files with 2,817 additions and 17 deletions.
522 changes: 522 additions & 0 deletions games/war.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion myCpps/!-OJcreater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using namespace std;

//***************************************
const string CPPfile = "knightInWarGrid_UVA11906"; //*
const string CPPfile = "flightPlanner_UVA10337"; //*
//***************************************

ifstream fin(CPPfile + ".cpp");
Expand Down
67 changes: 67 additions & 0 deletions myCpps/ECoins_UVA10306.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <bits/stdc++.h>

using namespace std;

ifstream fin("ECoins_UVA10306.in");
ofstream fout("ECoins_UVA10306.out");

struct coin
{
int x;
int y;
};

int main()
{
int testCase; fin >> testCase;
for (int t = 1; t <= testCase; ++t)
{
int m, s; fin >> m >> s;

vector<coin> a(m);
for (int i = 0; i <= m - 1; ++i)
{
fin >> a[i].x >> a[i].y;
}

vector<vector<int>> dp(s + 1, vector<int>(s + 1, INT_MAX));

int ans = INT_MAX;
dp[0][0] = 0;

for (int i = 0; i <= s; ++i)
{
for (int j = 0; j <= s; ++j)
{
for (int k = 0; k <= m - 1; ++k)
{
if (i - a[k].x < 0 || j - a[k].y < 0)
{
continue;
}

if (dp[i - a[k].x][j - a[k].y] < INT_MAX)
{
dp[i][j] = min(dp[i][j], dp[i - a[k].x][j - a[k].y] + 1);
}

if (i * i + j * j == s * s && dp[i][j] < INT_MAX)
{
ans = min(ans, dp[i][j]);
}
}
}
}

if (ans == INT_MAX)
{
fout << "not possible\n";
}
else
{
fout << ans << '\n';
}
}

return 0;
}
85 changes: 85 additions & 0 deletions myCpps/ECoins_UVA10306.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
9
2 5
0 2
2 0

3 20
0 2
2 0
2 1
3 5
3 0
0 4
5 5
3 5
3 0
0 4
1 1
4 13
0 1
0 5
0 2
0 3
4 11
1 0
2 0
3 0
10 0

10 13
1 0
2 2
2 0
3 3
6 12
3 11
7 13
14 14
0 5
0 4

2 300
3 0
300 1

40 300
1 0
2 2
2 0
3 3
6 12
3 11
7 13
14 14
0 5
0 4
1 0
2 2
2 0
3 3
6 12
3 11
7 13
14 14
0 5
0 4
1 0
2 2
2 0
3 3
6 12
3 11
7 13
14 14
0 5
0 4
1 0
2 2
2 0
3 3
6 12
3 11
7 13
14 14
0 5
0 4
9 changes: 9 additions & 0 deletions myCpps/ECoins_UVA10306.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
not possible
10
2
2
3
2
3
100
18
69 changes: 69 additions & 0 deletions myCpps/ECoins_UVA10306OJ.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <bits/stdc++.h>

using namespace std;


struct coin
{
int x;
int y;
};

int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int testCase; cin >> testCase;
for (int t = 1; t <= testCase; ++t)
{
int m, s; cin >> m >> s;

vector<coin> a(m);
for (int i = 0; i <= m - 1; ++i)
{
cin >> a[i].x >> a[i].y;
}

vector<vector<int>> dp(s + 1, vector<int>(s + 1, INT_MAX));

int ans = INT_MAX;
dp[0][0] = 0;

for (int i = 0; i <= s; ++i)
{
for (int j = 0; j <= s; ++j)
{
for (int k = 0; k <= m - 1; ++k)
{
if (i - a[k].x < 0 || j - a[k].y < 0)
{
continue;
}

if (dp[i - a[k].x][j - a[k].y] < INT_MAX)
{
dp[i][j] = min(dp[i][j], dp[i - a[k].x][j - a[k].y] + 1);
}

if (i * i + j * j == s * s && dp[i][j] < INT_MAX)
{
ans = min(ans, dp[i][j]);
}
}
}
}

if (ans == INT_MAX)
{
cout << "not possible\n";
}
else
{
cout << ans << '\n';
}
}

cout.flush();
return 0;
}

34 changes: 34 additions & 0 deletions myCpps/barCodes_UVA10721.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <bits/stdc++.h>

using namespace std;

ifstream fin("barCodes_UVA10721.in");
ofstream fout("barCodes_UVA10721.out");

int main()
{
while (true)
{
long long n = 0, k = 0, m = 0; fin >> n >> k >> m;
if (n + k + m == 0) break;

vector<vector<long long>> dp(k + 1, vector<long long>(n + 1, 0));

dp[0][0] = 1;
for (int i = 1; i <= k; ++i)
{
for (int j = 1; j <= n; ++j)
{
for (int t = 1; t <= j; ++t)
{
if (t > m) break;
dp[i][j] += dp[i - 1][j - t];
}
}
}

fout << dp[k][n] << '\n';
}

return 0;
}
Loading

0 comments on commit f60bb51

Please sign in to comment.