日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

【每日一题】8月12日题目精讲 Mr. Kitayuta, the Treasure Hunter

發(fā)布時(shí)間:2023/12/3 编程问答 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【每日一题】8月12日题目精讲 Mr. Kitayuta, the Treasure Hunter 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

來(lái)源:牛客網(wǎng):

時(shí)間限制:C/C++ 1秒,其他語(yǔ)言2秒 空間限制:C/C++ 262144K,其他語(yǔ)言524288K 64bit IO Format: %lld

題目描述

The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are n gems in the Shuseki Islands in total, and the i-th gem is located on island pi.

Mr. Kitayuta has just arrived at island 0. With his great jumping ability, he will repeatedly perform jumps between islands to the east according to the following process:

First, he will jump from island 0 to island d.
After that, he will continue jumping according to the following rule. Let l be the length of the previous jump, that is, if his previous jump was from island prev to island cur, let l?=?cur?-?prev. He will perform a jump of length l?-?1, l or l?+?1 to the east. That is, he will jump to island (cur?+?l?-?1), (cur?+?l) or (cur?+?l?+?1) (if they exist). The length of a jump must be positive, that is, he cannot perform a jump of length 0 when l?=?1. If there is no valid destination, he will stop jumping.
Mr. Kitayuta will collect the gems on the islands visited during the process. Find the maximum number of gems that he can collect.

輸入描述:
The first line of the input contains two space-separated integers n and d (1?≤?n,?d?≤?30000), denoting the number of the gems in the Shuseki Islands and the length of the Mr. Kitayuta’s first jump, respectively.

The next n lines describe the location of the gems. The i-th of them (1?≤?i?≤?n) contains a integer pi (d?≤?p1?≤?p2?≤?…?≤?pn?≤?30000), denoting the number of the island that contains the i-th gem.

輸出描述:
Print the maximum number of gems that Mr. Kitayuta can collect.

示例1
輸入
復(fù)制

4 10 10 21 27 27

輸出
復(fù)制

3

示例2
輸入
復(fù)制

8 8 9 19 28 36 45 55 66 78

輸出
復(fù)制

6

示例3
輸入
復(fù)制

13 7 8 8 9 16 17 17 18 21 23 24 24 26 30

輸出
復(fù)制

4

備注:

In the first sample, the optimal route is 0 ?→? 10 (+1 gem) ?→? 19 ?→?
27 (+2 gems) ?→?…

In the second sample, the optimal route is 0 ?→? 8 ?→? 15 ?→? 21?→? 28
(+1 gem) ?→? 36 (+1 gem) ?→? 45 (+1 gem) ?→? 55 (+1 gem) ?→? 66 (+1
gem) ?→? 78 (+1 gem) ?→?…

In the third sample, the optimal route is 0 ?→? 7 ?→? 13 ?→? 18 (+1
gem) ?→? 24 (+2 gems) ?→? 30 (+1 gem) ?→?…

題意:

一維坐標(biāo)共有30001個(gè),坐標(biāo)從0~30000,其中有n個(gè)坐標(biāo)有寶座,起始點(diǎn)為0,給出第一步跳躍距離d,之后每一步可以從上一步x的基礎(chǔ)上選擇x,x-1,x+1。
問(wèn)最多能拿多少寶藏?

題解:

第一反應(yīng)是dp
dp[i][j]表示到達(dá)第i個(gè)島嶼,跳的距離為j得到的最大寶藏?cái)?shù)
從上一次狀態(tài)之后,可以跳三種情況,j,j+1,j-1,由此可得
dp[i+j][j]=max(dp[i+j][j],dp[i][j]+c[i+j])
dp[i+j+1][j+1]=max(dp[i+j+1][j+1],dp[i][j]+c[i+j+1])
dp[i+j-1][j-1] = max(dp[i+j-1][j-1], dp[i][j] + c[i+j-1])
我們將上面三個(gè)式子可以整合在一起:
dp[i][j]=max(dp[i][j],dp[next][j+k]+gem[i])
k的范圍是-1~1
next=i -( j + d - 250 )

第一維數(shù)組開30000
第二維不能再開這么大,
我們算一算最大步長(zhǎng)為1+2+3+…a+250 > 30000,所以最大也就是從第一次d的基礎(chǔ)上上下浮動(dòng)250,所以開500+夠用
我們規(guī)定 j=250 時(shí)表示和d相等,每次可以跳d,d-1,d+1,而下下次又是再上次基礎(chǔ)上加減1和不變,所以( j -250 )+d表示當(dāng)前跳躍的距離,i-(j-250)-d表示上一次的位置

代碼:

#include<bits/stdc++.h> using namespace std; const int maxn=30013; int gem[maxn]; int dp[maxn][520]; int main() {int n,d;cin>>n>>d;int sum=0;for(int i=1;i<=n;i++){int x;cin>>x;gem[x]++;//記錄寶藏坐標(biāo)數(shù)量 } memset(dp,-1,sizeof(dp));dp[d][250]=gem[d];//相當(dāng)于把250當(dāng)做0步//每次移動(dòng)就是250上下浮動(dòng) for(int i=d;i<=30000;i++)//i表示當(dāng)前距離 {for(int j=1;j<=500;j++){int jump=(j+d-250);//表示跳的距離 int next=i-jump;//表示上一次的位置 if(next<0||next>=i)continue;//不往回跳 //上一次的位置一定在當(dāng)前位置之前,否則成了向后跳for(int k=-1;k<=1;k++){if(j+k>0&&dp[next][j+k]!=-1)dp[i][j]=max(dp[i][j],dp[next][j+k]+gem[i]);//轉(zhuǎn)移方程 }sum=max(sum,dp[i][j]);}}cout<<sum<<endl;return 0; }

總結(jié)

以上是生活随笔為你收集整理的【每日一题】8月12日题目精讲 Mr. Kitayuta, the Treasure Hunter的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲视频欧美视频 | 欧美在线一区二区 | 亚洲一区www | 67194少妇在线观看 | 色成人综合网 | 日韩欧美精品在线播放 | 婷婷丁香九月 | 久久伊人影视 | 超碰人人人人人人 | 97蜜桃网| 亚洲黄色小说图片 | 色七七久久| 无码精品一区二区免费 | 黄色国产在线观看 | 美女被日网站 | 欧美中出 | 毛片网站免费观看 | 黄色录像a级片 | 91cn.com| av网站观看 | 国产精品99久久久久久久久 | 国产高潮久久 | 91日批| 国产做爰高潮呻吟视频 | 美景之屋电影免费高清完整韩剧 | 日本极品丰满ⅹxxxhd | 国产综合一区二区 | 美女又爽又黄免费视频 | 亚洲第一在线视频 | 欧美碰碰碰 | 午夜精品一区二区三区在线观看 | 欧美影视一区二区三区 | 麻豆精品国产传媒av | 国产成人无码久久久精品天美传媒 | 国产亚洲精品久久久久久777 | 亚洲乱码一区二区三区 | 在线天堂中文在线资源网 | 超碰在线观看免费版 | 女人18毛片毛片毛片毛片区二 | 中文字幕av一区二区三区谷原希美 | 玖玖伊人 | 日韩久久一区二区 | 91在线观看网站 | 国产三级影院 | 久久久久久久久久久久久av | 国产强被迫伦姧在线观看无码 | 欧美成人手机视频 | 欧美激情影院 | a天堂亚洲 | 爱啪啪导航 | 在线看国产精品 | 精品性久久 | 午夜丁香婷婷 | 国产第一页在线观看 | 黄色在线网站 | 亚州av在线| 在线观看黄色网页 | 日韩乱码在线观看 | 日韩激情片 | 欧美夜夜 | 黑人玩弄人妻一区二区三区影院 | 欧美性视频一区二区三区 | 健身教练巨大粗爽gay视频 | 偷拍综合网 | 超碰97人| 一级特黄aaaaaa大片 | 丰满岳乱妇在线观看中字无码 | 国产激情综合 | 美女一区二区视频 | 性色av一区二区三区在线观看 | 黄色小网站入口 | 无码人妻精品一区二区三区在线 | 色妞综合网| 欧美激情精品久久久久久 | 91啪在线观看| 久久伊人国产 | 中文字幕日韩无 | 最近中文字幕免费 | 中文自拍 | 国产日韩精品在线观看 | 丰满人妻翻云覆雨呻吟视频 | 久久国产精品免费视频 | 欧美性受视频 | 日韩免费不卡视频 | 性久久| 国产在线视频一区 | 综合xx网 | 日韩一级片在线播放 | 丁香九月婷婷 | 色香蕉网 | 熟女毛毛多熟妇人妻aⅴ在线毛片 | 丁香婷婷深情五月亚洲 | 性插免费视频 | 国产精品国产三级国产专区51区 | 中文字幕乱码人妻一区二区三区 | 久久久久青草 | 久热国产精品 | 一级黄色录像大片 | 国产美女精品在线 |