Dương Hoàng
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Lời giải đề thi Tuyển sinh 10 trường Phổ thông Năng khiếu - năm 2025 - Môn Tin học Chấm bài tại đây: [ClueOJ](https://oj.clue.edu.vn/contest/ptnk_ts10_25). ## Bài 1 - STREAK ### Tóm tắt đề bài Cho dãy gồm $n$ xâu, mỗi xâu chỉ có dạng là `ONLINE` hoặc `OFFLINE` hoặc `IDLE`. Hãy tìm dãy các xâu **liên tiếp dài nhất**, mà các xâu trong đó đều là `ONLINE`. Giới hạn: $n \le 1440$. ### Lời giải Ta duy trì hai biến: - $cur$ là độ dài của dãy con **kết thúc tại vị trí $i$ đang xét**, mà toàn bộ là xâu `ONLINE`. Dễ thấy, nếu xâu thứ $i$ không phải là `ONLINE`, thì $cur = 0$. - $res$ là kết quả hiện tại. Ta thực hiện thuật toán như sau: với mỗi xâu $i$: - Nếu xâu thứ $i$ là `ONLINE`, đương nhiên $cur$ cộng thêm $1$, do ta có thêm một xâu. - Ngược lại, $cur = 0$, vì dãy con liên tiếp hiện tại không còn toàn bộ là `ONLINE` nữa. - Để tránh sai sót, dù vào trường hợp nào, ta đều cập nhật $res = max (res, cur)$. Độ phức tạp: $O$ $(n)$. ## Bài 2 - EVTRIP ### Tóm tắt đề bài Có một chiếc xe điện với dung lượng pin là $P$ đơn vị. Để di chuyển $1$ $km$ tốn $1$ đơn vị pin. Xe hết pin sẽ không thể di chuyển. Có $N$ trạm sạc pin cho xe nằm tại các vị trí $a_1, a_2, ..., a_N$. Mỗi lần sạc thì pin sẽ về dung lượng tối đa là $P$ đơn vị. Bạn sẽ bắt đầu ở vị trí $0$ $km$ với quả pin đầy. Hãy tìm cách di chuyển đến vị trí $D$ mà sạc ít lần nhất. Giới hạn: $N \le 1000$, $P, D \le 10^9$, $a_i < D$. ### Lời giải - Để tiện xử lý, ta sẽ sắp xếp các trạm sạc theo thứ tự tăng dần. Đồng thời, ta coi như $a_0 = 0$ vì ở vị trí $0$ pin đã đầy, nên ta coi vị trí $0$ cũng có trạm sạc. - Ta sẽ quy hoạch động: gọi $dp[i]$ là **số lần sạc pin tối thiểu**, khi ta **có đầy pin ở vị trí $a_i$**, và **ta có sạc ở trạm $a_i$**. - Để có thể đến trạm $a_i$ thì ta sẽ phải đầy pin ở một trạm $a_j$ với $j < i$ nào đó, mà $a_i - a_j \le P$. - Vì vậy, ban đầu $dp[i] = \inf$, chỉ có $dp[0] = 0$. Ta có công thức truy hồi: $dp[i] = min (dp[j] + 1)$ với $0 \le j < i$ và $a_i - a_j \le P$. - Kết quả sẽ là $min$ của các $dp[i]$ thỏa mãn $D - a[i] \le P$ để ta có đủ điện. Cần lưu ý trường hợp không cần sạc lần nào, đó là khi $D \le P$. Độ phức tạp: $O$ $(N^2)$. ## Bài 3 - WORDGAME ### Tóm tắt đề bài Cho một xâu $s$ chỉ gồm các ký tự in thường. Hãy loại bỏ ít ký tự nhất, mà sau khi loại bỏ xâu $s$ là xâu đối xứng. Giới hạn: độ dài xâu $s \le 2000$. ### Lời giải - Ta sẽ định nghĩa lại bài toán: Ta cần tìm xâu con dài nhất (có thể không cần liên tiếp) của xâu $s$, mà xâu đó là xâu đối xứng. - Bài toán này có thể xử lý bằng quy hoạch động. - Gọi $dp[i][j]$ là độ dài xâu con dài nhất trong xâu $s[i] \rightarrow s[j]$ mà xâu đó là xâu đối xứng - Ta có công thức truy hồi: - $dp[i][i] = 1$ với mọi $1 \le i \le n$. - $dp[i][i + 1] = 2$ với mọi $1 \le i < n$ và $s_i = s{i + 1}$. - $dp[i][j] = dp[i + 1][j - 1] + 2$ với $s_i = s_j$. - $dp[i][j] = max (dp[i + 1][j], dp[i][j - 1])$ với $s_i \neq s_j$. - Kết quả sẽ là $n - dp[1][n]$ do $dp[1][n]$ là độ dài xâu con dài nhất trong $s$ mà xâu đó là xâu đối xứng. Độ phức tạp: $O$ $(n^2)$ ## Bài 4 - BLOCKOPT ### Tóm tắt đề bài Cho $n$ đồ vật, đồ vật thứ $i$ có giá trị là $f_i$ và giá mua là $s_i$, mỗi đồ vật chỉ có số lượng là $1$. Bạn có $m$ đồng để mua các đồ vật, và bạn cần mua các đồ vật sao cho tổng giá trị là lớn nhất, mà tổng giá mua $\le m$. Tuy vậy, có $k$ ràng buộc dạng $(a, b)$ có nghĩa: nếu bạn mua vật $a$ thì phải mua vật $b$. $k$ ràng buộc này không tạo thành chu trình. Giới hạn: $n \le 50$, $f_i, s_i, m \le 1000$. ### Lời giải Bài toán này là bài toán thuộc NP-hard, vì vậy **không có lời giải chính xác trong thời gian đa thức.** Dưới đây chỉ là cách mình dựa vào để sinh test. ### Với $n \le 25$ Với giới hạn này, ta hoàn toàn có thể duyệt mọi tập con của $n$ phần tử. Sau đó, ta cần kiểm tra tập con này có thỏa mãn không. Trước hết, ta cần kiểm tra tập con này có thỏa mãn $k$ điều kiện nói trên không. Có thể duyệt đủ $k$ điều kiện, tuy nhiên điều này là khá chậm. Ta có thể làm cách khác: - Với mỗi điều kiện $i$, ta sẽ lưu các **vật phẩm phải mua** nếu mua vật phẩm thứ $i$ **dưới dạng bitmask.** - Sau đó, ta có thể dễ dàng kiểm tra bằng phép toán AND hai tập hợp. Gọi $mask$ là tập con của $n$ phần tử ta đang thử, $must$ là tập các vật phẩm phải mua khi mua vật phẩm $i$ (mà vật phẩm $i$ cũng phải nằm trong $mask$), thì tập này thỏa mãn nếu $mask$ $\&$ $must = must$. Sau đó, ta cần tính tổng số tiền phải trả cho tập con này, nếu $\le m$ thì ta cập nhật vào kết quả. Độ phức tạp: $O$ $(2^n \times n)$, hằng số thấp do phép $\&$ khá nhanh. Một số cách nhánh cận: - Nếu tập ta đang duyệt, có tổng giá trị nhỏ hơn kết quả ta tìm thấy hiện tại, ta bỏ qua. - Chỉ cần vi phạm một trong $k$ điều kiện, ta sẽ $break$ sớm. ### Với $n \le 50$ Đến đây có thể có một số cách như: - Meet in the middle (độ phức tạp sẽ có dạng $2^x + 3^y$ với $x + y = n$). Ta sẽ chia $n$ thành hai tập $x$ và $y$ một cách tối ưu nhất. - DP bitmask và lưu khéo các trạng thái. - Tham lam, chẳng hạn theo tỷ lệ $\frac {f_i}{s_i}$. - [Leo đồi (hill climbing)](https://en.wikipedia.org/wiki/Hill_climbing). - [Luyện kim mô phỏng (simulated annealing)](https://en.wikipedia.org/wiki/Simulated_annealing), nâng cấp từ leo đồi. - [Tối ưu cục bộ (local search)](https://en.wikipedia.org/wiki/Local_search_(optimization)). - ~~if test~~. Do điều kiện chỉ cần sinh test, mình đã để thời gian chạy cho mỗi test case từ $5 - 7$ phút để cho ra kết quả tối ưu nhất, đồng thời bỏ qua các test có thuật giải đúng.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully