zoukankan      html  css  js  c++  java
  • BZOJ1270: [BeijingWc2008]雷涛的小猫

    1270: [BeijingWc2008]雷涛的小猫

    Time Limit: 50 Sec  Memory Limit: 162 MB
    Submit: 836  Solved: 392
    [Submit][Status]

    Description

    Input

    Output

    Sample Input

    Sample Output

    8

    HINT

    Source

     题解:

    水水的DP。。。

    考虑到n*m很小,所以我们可以从下往上DP,记录一个该行的最大值就可以O(1)转移了。

    代码:

     1 #include<cstdio>
     2 
     3 #include<cstdlib>
     4 
     5 #include<cmath>
     6 
     7 #include<cstring>
     8 
     9 #include<algorithm>
    10 
    11 #include<iostream>
    12 
    13 #include<vector>
    14 
    15 #include<map>
    16 
    17 #include<set>
    18 
    19 #include<queue>
    20 
    21 #include<string>
    22 
    23 #define inf 1000000000
    24 
    25 #define maxn 2100
    26 
    27 #define maxm 500+100
    28 
    29 #define eps 1e-10
    30 
    31 #define ll long long
    32 
    33 #define pa pair<int,int>
    34 
    35 #define for0(i,n) for(int i=0;i<=(n);i++)
    36 
    37 #define for1(i,n) for(int i=1;i<=(n);i++)
    38 
    39 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
    40 
    41 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
    42 
    43 #define mod 1000000007
    44 
    45 using namespace std;
    46 
    47 inline int read()
    48 
    49 {
    50 
    51     int x=0,f=1;char ch=getchar();
    52 
    53     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    54 
    55     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
    56 
    57     return x*f;
    58 
    59 }
    60 int f[maxn][maxn],n,m,h,mx[maxn];
    61 
    62 int main()
    63 
    64 {
    65 
    66     freopen("input.txt","r",stdin);
    67 
    68     freopen("output.txt","w",stdout);
    69 
    70     m=read();n=read();h=read();
    71     for1(i,m)
    72      {
    73          int x=read();
    74          for1(j,x)f[i][read()]++;
    75      }
    76     for1(i,n)
    77      {
    78         for1(j,m)f[j][i]+=max(f[j][i-1],mx[max(i-h,0)]);
    79         for1(j,m)mx[i]=max(mx[i],f[j][i]);
    80      }
    81     int ans=0; 
    82     for1(i,m)ans=max(ans,f[i][n]);
    83     printf("%d
    ",ans); 
    84 
    85     return 0;
    86 
    87 }
    View Code
  • 相关阅读:
    9-15
    9-5
    8-26
    8-24
    7-20
    7-17
    我离职后要干些什么
    6-18
    5-28
    5-20
  • 原文地址:https://www.cnblogs.com/zyfzyf/p/3979064.html
Copyright © 2011-2022 走看看