求大佬帮忙看看 第3 5是RE o(╥﹏╥)o

P1478 陶陶摘苹果(升级版)

threethree @ 2019-12-15 20:42:06

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include <vector>
using namespace std;

int main()
{
    int n, s;//苹果n 力气s;
    int a, b;//椅子高度a 手臂加升高b
    cin >> n >> s;
    cin >> a >> b;
    // //下标0有0者不用 //初始化
    vector<int> applehight(n + 1, 0);
    vector<int> needstrengh(s + 1, 0);
    for (int k = 1; k <= n; k++)
    {
        cin >> applehight[k] >> needstrengh[k];
    }
    //for (int k = 1; k <= n; k++)
    //{
    //  cout<< applehight[k] << needstrengh[k];
    //}
    vector<vector<int> > nslist(n + 1, vector<int>(s + 1));
    for (int i = 1; i <= n; i++)
    {//初始化
        for (int j = 1; j <= s; j++)
        {
            nslist[i][j] = 0;
        }
    }
    for (int i = 1; i <= n; i++)//对苹果循环
    {
        for (int j = 1; j <= s; j++)
        {
            if (j >= needstrengh[i] && applehight[i] <= a + b)
            {
                if (nslist[i - 1][j] > (nslist[i - 1][j - needstrengh[i]] + 1))
                    nslist[i][j] = nslist[i - 1][j];
                else if (nslist[i - 1][j] <= (nslist[i - 1][j - needstrengh[i]] + 1))
                    nslist[i][j] = nslist[i - 1][j - needstrengh[i]] + 1;
            }
            else
                nslist[i][j] = nslist[i - 1][j];
        }
    }
    //for (int i = 1; i <= n; i++)
    //{//初始化
    //  for (int j = 1; j <= s; j++)
    //  {
    //      cout<<nslist[i][j]<<" ";
    //      
    //  }
    //  cout << "\n";
    //}
    cout << nslist[n][s];
}

by threethree @ 2019-12-15 20:42:35

以及我是新人 不懂就问 怎么查看他的测试数据呀??


by 任胖子 @ 2019-12-17 13:34:11

@threethree 测试界面下面有“进入旧版”,点击进去就可以下载测试数据了。但是室是有限制的哦!


|