啧,YL 居然选了 Noip 的题来做练习?
唉,点了发布居然没有发布成功,神 TM 我写了一个下午,沃日 …… 垃圾 CSDN ……
直接放代码吧 ……
#include <bits/stdc++.h>
const int N = 10000 + 50 , M = 1000 + 50 ;
// using namespace std ;
int dp [ N ] [ M ] , tube [ N ] [ 3 ] ;
int x [ N ] , y [ N ] , tag [ N ] ;
int n , m , k , p , inf , ans ;
bool ok ;
int main ( ) {
scanf ( "%d%d%d" , & n , & m , & k ) ;
for ( int i = 0 ; i < n ; i ++ )
scanf ( "%d%d" , & x [ i ] , & y [ i ] ) ;
for ( int i = 1 ; i <= n ; i ++ )
tube [ i ] [ 0 ] = 0 , tube [ i ] [ 1 ] = m + 1 ;
for ( int i = 1 ; i <= k ; i ++ ) {
scanf ( "%d" , & p ) ;
tag [ p ] = 1 ;
scanf ( "%d%d" , & tube [ p ] [ 0 ] , & tube [ p ] [ 1 ] ) ;
}
memset ( dp , 0x7f , sizeof ( dp ) ) ;
inf = dp [ 0 ] [ 0 ] ;
for ( int i = 0 ; i <= m ; i ++ )
dp [ 0 ] [ i ] = 0 ;
for ( int i = 1 ; i <= n ; i ++ ) {
ok = true ;
for ( int j = x [ i - 1 ] + 1 ; j <= m ; j ++ )
dp [ i ] [ j ] = std :: min ( dp [ i ] [ j ] , std :: min ( dp [ i - 1 ] [ j - x [ i - 1 ] ] + 1 , dp [ i ] [ j - x [ i - 1 ] ] + 1 ) ) ;
for ( int j = 1 ; j <= m - y [ i - 1 ] ; j ++ )
dp [ i ] [ j ] = std :: min ( dp [ i ] [ j ] , dp [ i - 1 ] [ j + y [ i - 1 ] ] ) ;
for ( int j = m - x [ i - 1 ] ; j <= m ; j ++ )
dp [ i ] [ m ] = std :: min ( dp [ i ] [ m ] , std :: min ( dp [ i ] [ j ] + 1 , dp [ i - 1 ] [ j ] + 1 ) ) ;
for ( int j = 1 ; j <= tube [ i ] [ 0 ] ; j ++ )
dp [ i ] [ j ] = inf ;
for ( int j = tube [ i ] [ 1 ] ; j <= m ; j ++ )
dp [ i ] [ j ] = inf ;
for ( int j = 1 ; j <= m ; j ++ )
if ( dp [ i ] [ j ] < inf ) {
ok = false ;
break ;
}
if ( ! ok ) {
if ( tag [ i ] )
ans ++ ;
}
else break ;
}
if ( ok )
printf ( "0\n%d" , ans ) ;
else {
int cnt = inf ;
for ( int i = 1 ; i <= m ; i ++ )
cnt = std :: min ( cnt , dp [ n ] [ i ] ) ;
printf ( "1\n%d" , cnt ) ;
}
return 0 ;
}