Posted on 2009-07-01 12:39
Hero 阅读(132)
评论(0) 编辑 收藏 引用 所属分类:
代码如诗--ACM
1 //HLOJ 1026 Accepted 15 204 948 C++
2
3 #include <iostream>
4 using namespace std ;
5 const int size = 1200 ;
6 int dp[size] ;
7 int data[size] ;
8
9 int tnum ;
10 int ink, inn ;
11
12 int fmin( int x1, int x2, int x3, int x4, int x5, int x6 )
13 {
14 int reval = x1 ;
15 reval = reval < x2 ? reval : x2 ;
16 reval = reval < x3 ? reval : x3 ;
17 reval = reval < x4 ? reval : x4 ;
18 reval = reval < x5 ? reval : x5 ;
19 reval = reval < x6 ? reval : x6 ;
20
21 return reval ;
22 }
23
24 int main()
25 {
26 while( cin >> tnum )
27 {
28 while( tnum -- )
29 {
30 cin >> ink >> inn ;
31
32 memset( dp, 0, sizeof(dp) ) ;
33 memset( data, 0, sizeof(data) ) ;
34
35 for( int i=1; i<=inn; i++ )
36 {
37 cin >> data[i] ;
38 }
39
40 for( int i=1; i<=6; i++ ) dp[i] = data[i] ;
41 for( int i=7; i<=inn+1; i++ )
42 {
43 dp[i] = fmin( dp[i-1], dp[i-2], dp[i-3], dp[i-4], dp[i-5], dp[i-6] ) + data[i] ;
44 }
45
46 if( dp[inn+1] < ink )
47 printf( "YES\n" ) ;
48 else
49 printf( "NO\n" ) ;
50 }
51 }
52 return 0 ;
53 }