A - Super Jumping! Jumping! Jumping!
#include <iostream>
#define int long long
using namespace std;
const int maxn = 1000 + 5;
int a[maxn], dp[maxn];
signed main()
{
int n;
while (~scanf("%lld", &n), n)
{
for (int i = 0; i < n; i ++)
{
scanf("%lld", &a[i]);
dp[i] = 0;
}
for (int i = 0; i < n; i ++)
{
for (int j = 0; j < i; j ++)
{
if (a[j] < a[i] && dp[j] + a[i] > dp[i])
{
dp[i] = dp[j] + a[i];
}
}
if (dp[i] < a[i])
{
dp[i] = a[i];
}
}
int ans = 0;
for (int i = 0; i < n; i ++)
{
if (dp[i] > ans)
{
ans = dp[i];
}
}
printf("%lld\n", ans);
}
return 0;
}
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = 1000 + 5;
int dp[maxn][maxn];
char a[maxn], b[maxn];
int main()
{
while(cin >> a >> b)
{
int n1 = strlen(a);
int n2 = strlen(b);
for (int i = 0; i <= n1; i ++)
{
for (int j = 0; j <= n2; j ++)
{
dp[i][j] = 0;
}
}
for(int i = 1; i <= n1; i ++)
{
for(int j = 1; j <= n2; j ++)
{
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]);
}
}
}
cout << dp[n1][n2] << endl;
}
return 0;
}
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;
const int maxn = 1000 + 5;
int volume[maxn], worth[maxn], dp[maxn];
signed main()
{
int t;
cin >> t;
while (t --)
{
int n, v;
cin >> n >> v;
for (int i = 0; i < maxn; i ++)
{
dp[i] = 0;
}
for (int i = 1; i <= n; i ++)
{
scanf("%lld", &worth[i]);
}
for (int i = 1; i <= n; i ++)
{
scanf("%lld", &volume[i]);
}
for (int i = 1; i <= n; i ++)
{
for (int j = v; j >= volume[i]; j --)
{
dp[j] = max(dp[j], dp[j - volume[i]] + worth[i]);
}
}
cout << dp[v] << endl;
}
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;
const int inf = 0x3f3f3f;
const int maxn = 10000 + 5;
int dp[maxn];
int t;
int e, f;
int n;
int p, w;
int main()
{
scanf("%d", &t);
while (t --)
{
scanf("%d %d", &e, &f);
for (int i = 1;i <= f - e; i ++)
{
dp[i] = inf;
}
scanf("%d", &n);
while (n --)
{
scanf("%d %d", &p, &w);
for (int i = w; i <= f - e; i ++)
{
dp[i] = min(dp[i], dp[i - w] + p);
}
}
if(dp[f - e] == inf)
{
printf("This is impossible.");
}
else
{
printf("The minimum amount of money in the piggy-bank is %d.", dp[f - e]);
}
putchar('\n');
}
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 30 * 6 + 5;
struct temp
{
int x, y, z, dp;
}node[maxn];
bool cmp(temp t1, temp t2)
{
if (t1.x == t2.x) return t1.y < t2.y;
return t1.x < t2.x;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int Case = 0;
int n;
while(cin >> n, n)
{
int cnt = -1;
for(int i = 0; i < n;i ++)
{
int x, y, z;
cin >> x >> y >> z;
node[++ cnt].x=x, node[cnt].y=y, node[cnt].z = node[cnt].dp=z;
node[++ cnt].x=x, node[cnt].y=z, node[cnt].z = node[cnt].dp=y;
node[++ cnt].x=y, node[cnt].y=x, node[cnt].z = node[cnt].dp=z;
node[++ cnt].x=y, node[cnt].y=z, node[cnt].z = node[cnt].dp=x;
node[++ cnt].x=z, node[cnt].y=x, node[cnt].z = node[cnt].dp=y;
node[++ cnt].x=z, node[cnt].y=y, node[cnt].z = node[cnt].dp=x;
}
sort(node, node + cnt, cmp);
int ans = 0;
for(int i = 0;i < cnt; i ++)
{
for(int j = 0;j < cnt;j ++)
{
if(node[i].x > node[j].x && node[i].y > node[j].y)
{
node[i].dp = max(node[i].dp, node[j].dp + node[i].z);
}
ans = max(ans, node[i].dp);
}
}
cout << "Case " << ++ Case << ": maximum height = " << ans << endl;
}
return 0;
}
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = 2000 + 5;
int dp[maxn], one[maxn], two[maxn];
int main()
{
int n;
cin >> n;
while(n --)
{
memset(dp, 0, sizeof(dp));
memset(one, 0, sizeof(one));
memset(two, 0, sizeof(two));
int k;
scanf("%d", &k);
for(int i = 1; i <= k; i ++)
{
scanf("%d", &one[i]);
}
for(int i = 2; i <= k; i ++)
{
scanf("%d", &two[i]);
}
dp[0] = 0;
dp[1] = one[1];
for(int i = 2;i <= k; i ++)
{
dp[i] = min(dp[i - 1] + one[i], dp[i - 2] + two[i]);
}
int h = dp[k] / 3600 + 8;
int m = dp[k] / 60 % 60;
int s = dp[k] % 60;
printf("%02d:%02d:%02d am\n", h, m, s);
}
return 0;
}