zoukankan      html  css  js  c++  java
  • cf 506 A. Mr. Kitayuta, the Treasure Hunter

    不知道这个sb题怎么做错了。。

     1 /*#include <bits/stdc++.h>
     2 #define LL long long
     3 using namespace std;
     4 inline int ra()
     5 {
     6     int x=0,f=1; char ch=getchar();
     7     while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
     8     while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
     9     return x*f;
    10 }
    11 int n,s,tot[30005],f[30005],ans;
    12 bool can[30005][605];
    13 const int T=300;
    14 int main()
    15 {
    16     n=ra(); s=ra(); can[0][T]=1;
    17     for (int i=1; i<=n; i++) tot[ra()]++;
    18     f[0]=tot[0];
    19     for (int i=0; i<=30000; i++)
    20     {
    21         for (int j=-300; j<=300; j++)
    22         {
    23             if (s+j<=0) continue; 
    24             if (can[i][j+T] && s+i+j<=30000)
    25             {
    26                 f[s+i+j]=max(f[i+j+s],f[i]+tot[s+i+j]);
    27                 can[i+j+s][j+T]=1;
    28                 can[i+j+s][j+1+T]=1;
    29                 can[i+j+s][j-1+T]=1;
    30             }
    31         }
    32         ans=max(ans,f[i]);
    33     }
    34     cout<<ans;
    35     return 0;
    36 }*/
    37 #include <bits/stdc++.h>
    38 #define LL long long
    39 using namespace std;
    40 inline int ra()
    41 {
    42     int x=0,f=1; char ch=getchar();
    43     while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
    44     while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    45     return x*f;
    46 }
    47 const int T=600;
    48 int n,s,ans;
    49 int tot[30005],f[30005][605];
    50 int main()
    51 {
    52     memset(f,-1,sizeof(f));
    53     n=ra(); s=ra();
    54     for (int i=1; i<=n; i++) tot[ra()]++;
    55     f[s][T/2]=0;
    56     for (int i=s; i<=30000; i++)
    57         for (int j=1; j<=T; j++)
    58         {
    59             int t=j-T/2+s;
    60             if (i-t>=0 && t>0)
    61             {
    62                 if (f[i-t][j-1]!=-1) f[i][j]=max(f[i][j],f[i-t][j-1]);
    63                 if (f[i-t][j]!=-1) f[i][j]=max(f[i][j],f[i-t][j]);
    64                 if (f[i-t][j+1]!=-1) f[i][j]=max(f[i][j],f[i-t][j+1]);
    65                 if (f[i][j]!=-1) f[i][j]+=tot[i];
    66                 ans=max(f[i][j],ans);
    67             }
    68         }
    69         cout<<ans;
    70         return 0;
    71 }
  • 相关阅读:
    html 上传图片前预览
    php获取当月天数及当月第一天及最后一天、上月第一天及最后一天实现方法
    php 计算 pdf文件页数
    php 获取半年内每个月的订单数量, 总价, 月份
    php 获取两个数组之间不同的值
    小程序支付功能
    关于nginx的Job for nginx.service failed because the control process exited with error code.错误
    linux 安装 Apollo
    MongoDB待续。。。
    ABP vNext...待续
  • 原文地址:https://www.cnblogs.com/ccd2333/p/6512063.html
Copyright © 2011-2022 走看看