这题我居然调了一下午……
看来我这种弱渣还是应该去考普及……
QAQ
DQS学长告诉我,想练DP的话去打这道题吧……
我就乖乖的去了
毕竟这题困扰了我两年……233333
打完之后DQS学长来嘲讽我:“我一年前就花两天做出来了……一年之后你还是得花一下午……”
QAQ DQS学长真是太神了……OrzOrz
代码丑的没法看……
待我调整下习惯再说QAQ
改之前
#include
#include
#include
#include
#define KILL puts("haha");
using namespace std;
const int MAXN = 10000 + 5;
const int MAXM = 1000 + 5;
const int INF = 1061109567;
struct dot
{
int up,down,up_killer,down_killer,num;
}d[MAXN];
int n,m;
int dp[MAXN][MAXM];
void pack(int k,int up,int down)
{
for(int i = 1;i <= m;i ++)
{
dp[k + 1][min(i + up,m)] = min(dp[k + 1][min(i + up,m)],min(dp[k][i],dp[k + 1][i]) + 1);
}
for(int i = down + 1;i <= m;i ++)
{
if(dp[k][i] == INF)
continue;
dp[k + 1][i - down] = min(dp[k + 1][i - down],dp[k][i]);
}
return;
}
int k;
int p;
int what[MAXN];
int main()
{
memset(dp,0x3f,sizeof(dp));
scanf("%d %d %d",&n,&m,&k);
for(int i = 0;i < n;i ++)
scanf("%d %d",&d[i].up,&d[i].down),d[i].up_killer = m + 1;
for(int i = 1;i <= k;i ++)
{
scanf("%d",&p);
scanf("%d %d",&d[p].down_killer,&d[p].up_killer);
what[i] = p;
d[p].num = true;
}
for(int i = 1;i <= m;i ++)
dp[0][i] = 0;
for(int i = 0;i < n;i ++)
{
for(int j = d[i].up_killer;j <= m;j ++)
dp[i][j] = INF;
for(int j = 0;j <= d[i].down_killer;j ++)
dp[i][j] = INF;
pack(i,d[i].up,d[i].down);
}
sort(what + 1,what + k + 1);
int ans = INF;
for(int i = 1;i <= m;i ++)
ans = min(ans,dp[n][i]);
if(ans == INF)
{
puts("0");
for(int i = n;i >= 0;i --)
{
if(d[i].num)
{
for(int j = 1;j <= m;j ++)
if(dp[i][j] != INF)
{
int temp = lower_bound(what + 1,what + k + 1,i) - (what);
printf("%d\n",temp);
return 0;
}
}
}
puts("0");
}
else
{
puts("1");
printf("%d\n",ans);
}
return 0;
}
改之后
#include
#include
#include
#include
#define KILL puts("haha");
using namespace std;
const int MAXN = 10000 + 5;
const int MAXM = 1000 + 5;
const int INF = 1061109567;
struct dot
{
int up,down,up_killer,down_killer;
}d[MAXN];
int n,m;
int dp[MAXN][MAXM];
void pack(int k,int up,int down)
{
for(int i = 1;i <= m;i ++)
dp[k + 1][min(i + up,m)] = min(dp[k + 1][min(i + up,m)],min(dp[k][i],dp[k + 1][i]) + 1);
for(int i = down + 1;i <= m;i ++)
dp[k + 1][i - down] = min(dp[k + 1][i - down],dp[k][i]);
return;
}
int k,p,sum[MAXN],ans = INF;
int where()
{
for(int i = n;i >= 0;i --)
for(int j = 1;j <= m;j ++)
if(dp[i][j] != INF)
return sum[i];
}
int main()
{
scanf("%d %d %d",&n,&m,&k);
memset(dp,0x3f,sizeof(dp));
for(int i = 0;i < n;i ++)
scanf("%d %d",&d[i].up,&d[i].down),d[i].up_killer = m + 1;
for(int i = 1;i <= k;i ++)
{
scanf("%d",&p);
scanf("%d %d",&d[p].down_killer,&d[p].up_killer);
sum[p] = 1;
}
for(int i = 1;i <= n;i ++)
sum[i] += sum[i - 1];
for(int i = 1;i <= m;i ++)
dp[0][i] = 0;
for(int i = 0;i < n;i ++)
{
for(int j = d[i].up_killer;j <= m;j ++)
dp[i][j] = INF;
for(int j = 0;j <= d[i].down_killer;j ++)
dp[i][j] = INF;
pack(i,d[i].up,d[i].down);
}
for(int i = 1;i <= m;i ++)
ans = min(ans,dp[n][i]);
if(ans == INF)
printf("0\n%d\n",where());
else
printf("1\n%d\n",ans);
return 0;
}
dqs学长真是太神了~~~
OI虐完我之后又用MarkDown虐了我一遍QAQ
果然我还是去考NOIP吧……