wa70求助

P1280 尼克的任务

应该是需要将dp数组初始化成-inf,否则会从不合法的地方转移过来。比如:(1,4)、(2,3)、(6,7)。
by 是青白呀 @ 2023-10-24 21:03:17


其实正着往后转移会更好写一点。就是在第一个循环里: ``` for(int i=1;i<=k-1;i++){ if(dp[i]==-inf)continue; p[i].id=i; int pos=upper_bound(p+1,p+1+k,(node){p[i].ri,0,0,0})-p; int now=p[pos].le; while(p[pos].le==now){ dp[pos]=max(dp[pos],dp[i]+p[pos].le-p[i].ri-1; pos++; } } ``` 最后的答案是 `dp[k]`。
by 是青白呀 @ 2023-10-24 21:06:01


@[是青白呀](/user/359270) 射射大佬,还得是您!
by LingHusama @ 2023-10-24 21:14:43


@[是青白呀](/user/359270) 虽然确实是初始化的问题,但是好像您的这个hack对我的代码而言输出都一样吧……(我还在雾里)
by LingHusama @ 2023-10-24 21:27:24


@[LingHusama](/user/275989) hack 给的是上班时间的左右端点,没注意到输入给的是时长(捂脸)
by 是青白呀 @ 2023-10-24 21:41:25


@[LingHusama](/user/275989) 还有就是 最新提交的代码里初始化成0x3f 是 63,会不会有点小了?
by 是青白呀 @ 2023-10-24 21:42:38


@[是青白呀](/user/359270) memset里面0x3f就是极大值吧
by LingHusama @ 2023-10-24 21:46:20


@[是青白呀](/user/359270) 毕竟memset是把每个字节初始化为设置的那个东西,int四个字节就是0x3f3f3f3f
by LingHusama @ 2023-10-24 21:50:11


@[LingHusama](/user/275989) 哦对!
by 是青白呀 @ 2023-10-24 22:34:01


|