caioj1522: [NOIP提高組2005]過河

狀態壓縮的經典題。

按照一般做法,DP一維時間O(n),顯然跑不過。考慮到石子較少,實際上有很長一段是一定可以跳到的,設兩個石頭分別在i點和j點,跳躍的路程為S到T。那么從i點可以跳到i+S到i+T。從j-T到j-S可以跳到J。顯然當i和j相隔非常非常遠時,從i到i+T中必然可以經過若干次跳躍,然后跳到j-T到j的任意一段。

然后狀壓,可以發現距離大于90(假設s和t不同,s(9)和t(10)的最小公倍數)一定可以到達,這樣我們把石頭之間的距離%90節省時間。

然后特判一下s==t的情況,就可以AC。但有一個問題,我將mod變成100,不特判s==t的情況,這樣會WA,這個我無法理解。

?

數據:10000
7 7 100
1111 1118 1114 1117 3010 7508 1119 1105 899 1112 9667 3238 1108 5178 4627 2116 2089 9184 1115 8887 3565 3560 3559 3562 2410 3564 3571 565 3561 3566 3573 7432 9485 4484 7258 4555 8812 1291 3567 3221 5252 5253 5244 797 5251 7885 5245 9340 5255 6537 7737 5243 9316 5246 6694 6773 5247 6031 5256 5249 5484 5482 7513 5485 5479 5481 5480 5489 381 2572 9255 7624 5821 8606 7829 5488 442 5490 5492 8098 483 482 481 478 469 474 4054 472 471 4407 479 7006 475 470 3147 6933 9097 7781 473 2221
應該輸出10但是改了輸出13.

?

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int se[110],a[1100000],f[1100000];
int main()
{int L,s,t,n;scanf("%d%d%d%d",&L,&s,&t,&n);for(int i=1;i<=n;i++)scanf("%d",&se[i]);sort(se+1,se+n+1);if(s==t){int ans=0;for(int i=1;i<=n;i++)if(se[i]%s==0)ans++;printf("%d\n",ans);return 0;}for(int i=1;i<=n;i++)se[i]=se[i-1]+(se[i]-se[i-1])%90;L=(L-se[n])%90+se[n];for(int i=1;i<=n;i++)a[se[i]]=1;memset(f,63,sizeof(f));f[0]=0;for(int i=s;i<=L+t;i++)for(int j=s;j<=t;j++)if(i>=j)f[i]=min(f[i],f[i-j]+a[i]);int ans=999999999;for(int i=L;i<L+t;i++)ans=min(ans,f[i]);printf("%d\n",ans);return 0;
}

?

轉載于:https://www.cnblogs.com/AKCqhzdy/p/7616899.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/391230.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391230.shtml
英文地址,請注明出處:http://en.pswp.cn/news/391230.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Dev控件使用CheckedListBoxControl獲取items.count為0 的解決方法

CheckedListBoxControl&#xff0c;我使用DataSource屬性&#xff0c;給其綁定了一個List對象。界面顯示都挺正常的&#xff0c;當若干個項的復選框被選中的后&#xff0c;它的checkedListBoxControl1.CheckedItems也是正常的。 唯獨的問題是在代碼中得到的checkedListBoxContr…

如何啟動軟件YouTube頻道

Hi, I’m Beau and I run the freeCodeCamp.org YouTube channel. 嗨&#xff0c;我是Beau&#xff0c;我運行了freeCodeCamp.org YouTube頻道 。 For the first few years of our channel’s life, we had less than 100,000 subscribers. When we published new videos, we …

【powerdesign】從mysql數據庫導出到powerdesign,生成數據字典

使用版本powerdesign16.5&#xff0c;mysql 5.5&#xff0c;windows 64 步驟&#xff1a; 1.下載mysql驅動【注意 32和64的驅動都下載下來&#xff0c;具體原因查看第三步 依舊會報錯處】 下載地址&#xff1a;https://dev.mysql.com/downloads/connector/odbc/5.3.html 請下…

php amazon-s3_推薦亞馬遜電影-一種協作方法

php amazon-s3Item-based collaborative and User-based collaborative approach for recommendation system with simple coding.推薦系統的基于項目的協作和基于用戶的協作方法&#xff0c;編碼簡單。 推薦系統概述 (Overview of Recommendation System) There are many met…

[高精度乘法]BZOJ 1754 [Usaco2005 qua]Bull Math

模板題目&#xff0c;練練手~ #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> using namespace std;int s1[2333]; int s2[2333]; int Out[2333]; string one,two;void Debug(){for(int i0;i<one.length();i){pri…

python:使用Djangorestframework編寫post和get接口

1、安裝django pip install django 2、新建一個django工程 python manage.py startproject cainiao_monitor_api 3、新建一個app python manage.py startapp monitor 4、安裝DRF pip install djangorestframework 5、編寫視圖函數 views.py from rest_framework.views import A…

Kubernetes 入門(3)集群安裝

1. kubeadm簡介 kubeadm 是 Kubernetes 官方提供的一個 CLI 工具&#xff0c;可以很方便的搭建一套符合官方最佳實踐的最小化可用集群。當我們使用 kubeadm 搭建集群時&#xff0c;集群可以通過 K8S 的一致性測試&#xff0c;并且 kubeadm 還支持其他的集群生命周期功能&#…

Angular Material 攻略 04 Icon

Icon 網頁系統中的Icon雖然說很簡單&#xff0c;但是其中的學問還是有很多的&#xff0c;我們常用的Icon庫有FontAwesome、Iconfont等&#xff0c;我們選擇了Angular Material這個組件庫&#xff0c;就介紹Material Icons吧。 對Icon感興趣的同學可以看一下這里 Material Desig…

【9303】平面分割

Time Limit: 10 second Memory Limit: 2 MB 問題描述 同一平面內有n&#xff08;n≤500&#xff09;條直線&#xff0c;已知其中p&#xff08;p≥2&#xff09;條直線相交與同一點&#xff0c;則這n條直線最多能將平面分割成多少個不同的區域&#xff1f; Input 兩個整數n&am…

簡述yolo1-yolo3_使用YOLO框架進行對象檢測的綜合指南-第一部分

簡述yolo1-yolo3重點 (Top highlight)目錄&#xff1a; (Table Of Contents:) Introduction 介紹 Why YOLO? 為什么選擇YOLO&#xff1f; How does it work? 它是如何工作的&#xff1f; Intersection over Union (IoU) 聯合路口(IoU) Non-max suppression 非最大抑制 Networ…

django:資源網站匯總

Django REST framework官網 http://www.sinodocs.cn/ django中文網 https://www.django.cn/ 轉載于:https://www.cnblogs.com/gcgc/p/11542068.html

Kubernetes 入門(4)集群配置

1. 集群配置 報錯&#xff1a; message: ‘runtime network not ready: NetworkReadyfalse reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized’ 原因&#xff1a;cni未被初始化&#xff08;CNI 是 Container Network In…

【例9.8】合唱隊形

【例9.8】合唱隊形 鏈接&#xff1a;http://ybt.ssoier.cn:8088/problem_show.php?pid1264 時間限制: 1000 ms 內存限制: 65536 KB【題目描述】 N位同學站成一排&#xff0c;音樂老師要請其中的(N-K)位同學出列&#xff0c;使得剩下的K位同學排成合唱隊形。 合唱隊形是…

scrum流程 規劃 沖刺_Scrum –困難的部分2:更快地沖刺

scrum流程 規劃 沖刺In the first part, I presented my favorite list of Scrums hard parts and how to work around them. In the second part, I offer you a colorful bouquet of workarounds as well. Have fun!在第一部分中 &#xff0c;我介紹了我最喜歡的Scrum困難部分…

JAVA基礎知識|lambda與stream

lambda與stream是java8中比較重要兩個新特性&#xff0c;lambda表達式采用一種簡潔的語法定義代碼塊&#xff0c;允許我們將行為傳遞到函數中。之前我們想將行為傳遞到函數中&#xff0c;僅有的選擇是使用匿名內部類&#xff0c;現在我們可以使用lambda表達式替代匿名內部類。在…

數據庫:存儲過程_數據科學過程:摘要

數據庫:存儲過程Once you begin studying data science, you will hear something called ‘data science process’. This expression refers to a five stage process that usually data scientists perform when working on a project. In this post I will walk through ea…

901

901 轉載于:https://www.cnblogs.com/Forever77/p/11542129.html

leetcode 137. 只出現一次的數字 II(位運算)

給你一個整數數組 nums &#xff0c;除某個元素僅出現 一次 外&#xff0c;其余每個元素都恰出現 三次 。請你找出并返回那個只出現了一次的元素。 示例 1&#xff1a; 輸入&#xff1a;nums [2,2,3,2] 輸出&#xff1a;3 示例 2&#xff1a; 輸入&#xff1a;nums [0,1,0,…

【p081】ISBN號碼

Time Limit: 1 second Memory Limit: 50 MB 【問題描述】 每一本正式出版的圖書都有一個ISBN號碼與之對應&#xff0c;ISBN碼包括9位數字、1位識別碼和3位分隔符&#xff0c;其規定格式如“x-xxx-xxxxx-x”&#xff0c;其中符號“-”是分隔符&#xff08;鍵盤上的減號&#xff…

gitlab bash_如何編寫Bash一線式以克隆和管理GitHub和GitLab存儲庫

gitlab bashFew things are more satisfying to me than one elegant line of Bash that automates hours of tedious work. 沒有什么比讓Bash自動完成數小時繁瑣工作的Bash優雅系列令我滿意的了。 As part of some recent explorations into automatically re-creating my la…