日韩性视频-久久久蜜桃-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ò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 一级黄色小视频 | 在线观看入口 | 三级免费看 | 曰韩av| 黄色的网站免费观看 | 久久久免费av | 黄色在线a | 亚洲第一免费 | 一本大道av伊人久久综合 | youjizz韩国| 国产精品污 | 国产精品乱码久久久久久久久 | 91国产在线看 | 日本裸体动漫 | 一区二区三区四区在线视频 | 四月婷婷 | 欧美日韩中文在线视频 | 国产成人三级在线观看视频 | www.四虎精品| 久久久久性色av无码一区二区 | 性欧美久久 | 一级片免费在线播放 | 手机看片一区二区三区 | 少妇在军营h文高辣 | 91人妻一区二区三区蜜臀 | 色综合久久久久综合体桃花网 | 麻豆av剧情 | 毛片av在线播放 | 国产成人精品一区二区三区免费 | 青青草原国产在线观看 | 国产精品www. | 狠狠操网站 | 性chinese天美传媒麻 | 中文字幕第一页在线视频 | 国产又粗又硬又黄的视频 | 国产精品黄在线观看 | 真性中出 | 91久久精品一区二区 | 毛片视频软件 | 69精品视频 | 亚洲乱乱 | 国产黄在线 | 欧美 在线 | 欧美一区二区三区成人精品 | 日本人妻伦在线中文字幕 | 男人靠女人免费视频网站 | 精品人妻一区二区三区久久 | 欧美1区2区3区4区 | 99热这里只有精品首页 | 草草影院国产 | 手机成人免费视频 | 全部毛片永久免费看 | 第四色在线视频 | 日本老年老熟无码 | 日韩欧美自拍 | 国产亚洲精品久久久久久久久动漫 | 国产美女视频一区二区 | 2一3sex性hd| 羞羞的视频在线观看 | 成人在线免费观看网站 | 亚洲午夜无码av毛片久久 | 国产精品一区二区三区久久 | 国产又黄又骚 | 国产精品久久久久久在线观看 | 青青草成人影视 | 欧美三级午夜理伦三级老人 | 久操视频在线 | a网站在线| 毛片在线视频 | 欧美日韩高清一区二区 国产亚洲免费看 | 欧美日本国产在线 | 一区二区不卡 | 假日游船 | 免费国产区 | 国产精品电影网站 | 少妇高潮伦 | 亚洲国产精品久久久久婷婷老年 | 欧美精品乱人伦久久久久久 | 干美女av | 夜夜精品一区二区无码 | 视色视频在线观看 | 国产乱视频 | 久久久久久久久99精品 | 97色婷婷 | 中文字幕在线观看1 | 中文字幕视频网 | 亚洲第一国产视频 | 欧洲综合视频 | jizz黑人| 精品人妻av一区二区三区 | 欧美拍拍视频 | 日本不卡一二三 | 中文字幕在线看高清电影 | 先锋影音久久 | 人妻偷人精品一区二区三区 | 成人午夜又粗又硬又大 | 欧美交受高潮1 | 天堂国产 | 91精品国产乱码久久久张津瑜 |