想了半天都没看出错误 T237953
  • 板块学术版
  • 楼主caojiaming
  • 当前回复4
  • 已保存回复4
  • 发布时间2023/1/29 16:44
  • 上次更新2023/10/24 02:40:56
查看原帖
想了半天都没看出错误 T237953
775551
caojiaming楼主2023/1/29 16:44

https://www.luogu.com.cn/training/275713#problems

#include <bits/stdc++.h>
using namespace std;
int t,m,t1[1005],a[1005];
int ans=-1;
void caojiaming(int step,int steptime,int stepsum)
{
    if(step==m+1)
    {
        if(stepsum>ans)
        {
            ans=stepsum;
        }
        return;
    }
    if(steptime+t1[step]>t)
    {
        caojiaming(step+1,steptime,stepsum);
    }
    else
    {
        caojiaming(step+1,steptime+t1[step],stepsum+a[step]);
    }
}
int main()
{
    scanf("%d%d",&t,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&t1[i],&a[i]);
    }
    caojiaming(1,0,0);
    cout<<ans;
    return 0;
}
2023/1/29 16:44
加载中...