E - Exam Study Planning Gym - 104790E

题目链接

题意:就是给你n个考试,每个考试给你四个元素,分别为考试开始时间,进行复习后的交卷时间,没有复习的交卷时间,以及复习花费的时间,问最大通过多少考试

#include 
using namespace std;
#define pi acos(-1)
#define xx first
#define yy second
#define endl "\n"
#define lowbit(x) x & (-x)
#define int long long
#define ull unsigned long long
#define pb push_back
typedef pair PII;
typedef pair PDD;
#define LF(x) fixed << setprecision(x)
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define Yshanqian ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
const int N = 1e6 + 10, M = 3010, inf = 0x3f3f3f3f, mod = 1e9 + 7, P = 13331;
const double eps = 1e-8;
int n;
int f[M][M]; // f[i][j]表示过了j个,当前这个i过或不过的最大剩余时间
void solve()
{
    cin >> n;
    for (int i = 0; i <= n; i++)
        for (int j = 1; j <= n; j++)
            f[i][j] = -1e18;
    int pre = 0;
    for (int i = 1; i <= n; i++)
    {
        int s, ex, ey, cost;
        cin >> s >> ex >> ey >> cost;
        for (int j = 0; j <= n; j++)
        {
            f[i][j] = max(f[i - 1][j] + s - pre, f[i][j]); // 当前第i个没过,那么过题数和前面应该相同,加上和上一个过题的时间间隔
            if (j == 0)
                continue;
            if (f[i - 1][j - 1] + s - pre >= cost) // 当前题可以过的情况,就是加上时间间隔后够复习第i个了
            {
                f[i][j] = max(f[i][j], f[i - 1][j - 1] + s - pre + ey - ex - cost); // 别忘了加上,ey-ex这一段的时间
            }
        }
        pre = ey;
    }
    for (int i = n; i >= 0; i--)
    {
        if (f[n][i] >= 0)
        {
            cout << i << endl;
            return;
        }
    }
}
signed main()
{
    Yshanqian;
    int T;
    T = 1;
    // cin >> T;
    for (int cases = 1; cases <= T; ++cases)
    {
        // cout<<"Case #"<

你可能感兴趣的:(c++,dp)