# 洛谷P1941飞扬的小鸟 完全背包

1.不能开滚动数组。
2.要特判飞过天花板的情况。
Code：

#include<cstdio>
#include<algorithm>
using namespace std;
const int maxm = 1009;
const int maxn = 10000 + 4;
const int inf  = 10000000 + 4;
int F[maxn][maxm], up[maxn], down[maxn], height[maxn];
int pipeup[maxn], pipedown[maxn], n,m,k, ans;
int main()
{
//freopen("in.txt","r",stdin);
scanf("%d%d%d",&n,&m,&k);
for(int i = 0;i < n;++i)
{
scanf("%d%d",&up[i],&down[i]);
height[i + 1] = m + up[i];
}
for(int i = 1;i <= k;++i)
{
int x;
scanf("%d",&x);
scanf("%d%d",&pipedown[x],&pipeup[x]);
}
height[0] = m;
F[0][0] = inf;
for(int i = 1;i <= n;++i)
{
for(int j = 1;j <= height[i]; ++j)F[i][j] = inf;
for(int j = 1;j <= height[i]; ++j)if(j - up[i-1] > 0)F[i][j] = min(F[i][j],F[i-1][j-up[i-1]] + 1);
for(int j = 1;j <= height[i]; ++j)if(j - up[i-1] > 0) F[i][j] = min(F[i][j], F[i][j-up[i-1]] + 1);
for(int j = 1;j <= m - down[i-1]; ++j)F[i][j] = min(F[i][j], F[i-1][j + down[i-1]]);
for(int j = m + 1;j <= height[i];++j)F[i][m] = min(F[i][m], F[i][j]);
for(int j = 1;j <= height[i]; ++j)
{
if(pipeup[i])
{
if(j >= pipeup[i] || j <= pipedown[i]) F[i][j] = inf;
}
if(F[i][j] < inf) ans = i;
}
}
if( ans == n)
{
printf("1\n");
int minv = inf;
for(int i = 1;i <= height[n]; ++i)
{
minv = min(minv,F[n][i]);
}
printf("%d",minv);
}
else{
printf("%d\n",0);
int cnt = 0;
for(int i = 1;i <= ans;++i)if(pipeup[i]) ++cnt;
printf("%d",cnt);
}
return 0;
}

09-07 227

02-11 571

11-09 41

10-30 22

04-08 27

02-10 37

10-24 623

07-27 70

07-06 316

#### 洛谷P1941 飞扬的小鸟

©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。