社区讨论
90pts玄关求调
P1156垃圾陷阱参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @m2bd5yd3
- 此快照首次捕获于
- 2024/10/16 12:20 去年
- 此快照最后确认于
- 2024/10/16 16:17 去年
CPP
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
//#include <windows.h>
//#include <psapi.h>
//#include <time.h>
using namespace std;
#define Formylove return 0;
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define debug(x) std::cerr << #x << '=' << x << std::endl
#define file(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
template <typename T>
void read(T &x)
{
char ch = getchar();
x = 0;
T f = 1;
while (ch != '-' && (ch < '0' || ch > '9'))
ch = getchar();
if (ch == '-')
f = -1, ch = getchar();
for (; ch >= '0' && ch <= '9'; ch = getchar())
x = x * 10 + ch - '0';
x *= f;
}
template <typename T>
void write(T x, bool flag)
{
x < 0 ? x = -x, putchar('-') : 0;
static short Stack[50], top(0);
do
Stack[++top] = x % 10, x /= 10;
while (x);
while (top)
putchar(Stack[top--] | 48);
flag ? putchar('\n') : putchar(' ');
}
int d, g;
struct node {
int t, f, h;
} p[105];
int dp[105][105];
bool cmp (node a, node b) {
return a.t < b.t;
}
int ansh, ansf;
signed main()
{
// file("Luogu_P_1156.cpp");
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// clock_t start,end; //定义clock_t变量
// start = clock(); //开始时间
read(d), read(g);
for (int i = 1; i <= g; ++i) {
read(p[i].t), read(p[i].f), read(p[i].h);
}
// end = clock(); //结束时间
// cout<<"time = "<<double(end-start)/CLOCKS_PER_SEC<<"s"<<endl;//输出时间
sort (p + 1, p + 1 + g, cmp);
dp[0][0] = 10;
for (int i = 1; i <= g; ++i) {
dp[i][0] = dp[i - 1][0] + p[i].f;
}
for (int i = 1; i <= g; ++i) {
for (int j = 0; j <= d; ++j) {
if (dp[i - 1][j] >= p[i].t) {
dp[i][j] = max (dp[i][j], dp[i - 1][j] + p[i].f);
}
if (j >= p[i].h and dp[i - 1][j - p[i].h] >= p[i].t) {
dp[i][j] = max (dp[i][j], dp[i - 1][j - p[i].h]);
}
}
}
for (int i = 1; i <= g; ++i) {
for (int j = 0; j <= d; ++j) {
// cout << dp[i][j] << ' ';
// dp[i][j] = max (10, dp[i][j]);
if (dp[i][j] >= p[i].t/* or p[i].t <= 10*/) {
ansh = max (ansh, j);
}
ansf = max (ansf, dp[i][j]);
}
if (ansh >= d) {
write(p[i].t, 1);
return 0;
}
}
// HANDLE hd = GetCurrentProcess();
// PROCESS_MEMORY_COUNTERS pmc;
// GetProcessMemoryInfo(hd, &pmc, sizeof(pmc));
// printf("%lf", double(pmc.WorkingSetSize) / 1024 / 1024);//单位MiB
write(ansf, 1);
// cout << endl;
Formylove
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...