开心的金明 火烧赤壁 南蛮图腾
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int n, m;
int v[30], k[30];
int arr[30010][30];
int main()
{
cin >> n >> m;
for (int i = 1;i <= m;i++)
{
cin >> v[i] >> k[i];
}
for (int i = 0;i <= n;i++)
{
for (int j = 0;j <= m;j++)
{
if (i >= v[j])
{
arr[i][j] = max(arr[i - v[j]][j - 1] + v[j] * k[j], arr[i][j - 1]);
}
else
{
arr[i][j] = arr[i][j-1];
}
}
}
cout << arr[n][m];
return 0;
}
#include<iostream>
#include<algorithm>
using namespace std;
struct xian {
int s;
int e;
};
xian arr[20010];
bool cmp(xian x1, xian x2)
{
if (x1.s == x2.s)
{
return x1.e < x2.e;
}
else return x1.s < x2.s;
}
int main()
{
int n;
cin >> n;
for (int i = 1;i <= n;i++)
{
cin >> arr[i].s >> arr[i].e;
}
sort(arr + 1, arr + 1 + n, cmp);
long long res = 0;
int endd;
for (int i = 1;i <= n;i++)
{
if (i == 1)
{
res = arr[i].e - arr[i].s;
endd = arr[i].e;
}
else
{
if (arr[i].s >= endd)
{
endd = arr[i].e;
res += arr[i].e - arr[i].s;
}
else if (arr[i].e > endd)
{
res += arr[i].e - endd;
endd = arr[i].e;
}
}
}
cout << res << endl;
return 0;
}
#include<iostream>
using namespace std;
// /\
// /__\
// / \ /\
// /__\/__\
char arr[4100][2100];
int main()
{
int n;
cin >> n;
arr[1][2] = '/';
arr[1][3] = '\\';
arr[2][1] = '/';
arr[2][2] = '_';
arr[2][3] = '_';
arr[2][4] = '\\';
int a = 2, b = 4;
for (int i = 1;i < n; i++)
{
for (int j = 1;j <= a;j++)
{
for (int z = 1;z <= b;z++)
{
arr[j + a][z] = arr[j][z];
arr[j + a][z + b] = arr[j][z];
arr[j][z] = ' ';
}
}
for (int j = 1;j <= a;j++)
{
for (int z = 1;z <= b;z++)
{
arr[j][z + a] = arr[j + a][z];
}
}
a *= 2;
b *= 2;
}
for (int i = 1;i <= a;i++)
{
for (int j = 1;j <= b;j++)
{
if (arr[i][j] != '/' && arr[i][j] != '_' && arr[i][j] != '\\')
{
cout << " ";
}
else
{
cout << arr[i][j];
}
}
cout << endl;
}
return 0;
}