Janoš Vidali
    • 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
      • 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 Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync 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
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
--- tags: vaje, or, dinamicno programiranje hackmd: https://hackmd.io/JnhxM8IfTaSFzMCVnKbo-A plugins: mathjax, mermaid --- # Operacijske raziskave - vaje 8.4.2021 --- ## Dinamično programiranje ### Naloga 1 Dan je niz $S = {a_1} {a_2} \dots {a_n}$, kjer so ${a_i}$ ($1 \le i \le n$) elementi neke končne abecede. Nizu ${a_j} {a_{j+1}} \dots {a_k}$, kjer je $1 \le j \le k \le n$, pravimo *strnjen podniz* niza $S$. S pomočjo dinamičnega programiranja napiši algoritem, ki določi najdaljši palindromski strnjen podniz v $S$. ---- * ${p_{jk}}$ ... ali je strnjen podniz ${a_j} {a_{j+1}} \dots {a_k}$ palindrom * ${p_{j,j-1}} = 1$ ($1 \le j \le n+1$) * ${p_{jj}} = 1$ ($1 \le j \le n$) * ${p_{jk}} = {p_{j+1,k-1}} \land {a_j} = {a_k}$ ($1 \le j < k \le n$) * računamo v leksikografskem vrstnem redu po $(k-j, j)$ * dolžina najdaljšega strnjenega podniza $p^* = \max \lbrace k-j+1 \mid 1 \le j \le k \le n, {p_{jk}} = 1 \rbrace$ * časovna zahtevnost: $O(n^2)$ * obstaja tudi algoritem, ki teče v času $O(n)$ --- ### Naloga 2 Dana je matrika <i>$A = (a_{ij})_{i,j=1}^{m,n}$</i>. Poiskati želimo strnjeno podmatriko matrike $A$ z največjo vsoto komponent. 1. Reši problem za matriko $$ A = \begin{pmatrix} 1 & -1 & 2 & 4 \\ -3 & -2 & 8 & 2 \\ -3 & 2 & -2 & 4 \\ 1 & -5 & -1 & -2 \end{pmatrix} . $$ 2. Napiši rekurzivne enačbe za opisani problem. 3. Napiši algoritem, ki reši opisani problem. Oceni tudi njegovo časovno zahtevnost v odvisnosti od $m$ in $n$. ---- * ${p_{hij}}$ ... največja vsota komponent podmatrike z vrsticami od $h+1$ do $i$ in zadnjim stolpcem $j$ * ${v_{ij}}$ ... vsota komponent do $i$-te vrstice v $j$-tem stolpcu * ${v_{0j}} = 0$ ($1 \le j \le n$) * ${v_{ij}} = {v_{i-1,j}} + {a_{ij}}$ ($1 \le i \le m$, $1 \le j \le n$) * ${p_{hi0}} = 0$ ($0 \le h < i \le m$) * ${p_{hij}} = {v_{ij}} - {v_{hj}} + \max \lbrace {p_{h,i,j-1}}, 0 \rbrace$ ($0 \le h < i \le m$, $1 \le j \le n$) * najprej izračunamo vrednosti ${v_{ij}}$ v leksikografskem vrstnem redu glede na $(i, j)$ * nato izračunamo vrednosti ${p_{hij}}$ v leksikografskem vrstnem redu glede na $(h, i, j)$ * največjo vsoto strnjene podmatrike dobimo kot $p^* = \max \lbrace {p_{hij}} \mid 0 \le h < i \le m, 0 \le j \le n \rbrace$ --- ### Naloga 3 Na ulici je $n$ vrstnih hiš, pri čemer je v $i$-ti hiši ${c_i}$ denarja. Tat se odloča, katere izmed hiš naj oropa. Vsak oropan stanovalec to sporoči svojim sosedom, zato tat ne sme oropati dveh sosednjih hiš. Ker je tat poslušal predmet Operacijske raziskave, pozna dinamično programiranje. Pokaži, kako naj tat določi, katere hiše naj oropa. ---- * ${p_i}$ ... največja količina, ki jo lahko naropa v prvih $i$ hišah * ${p_0} = 0$ * ${p_1} = \max \lbrace {c_1}, 0 \rbrace$ * ${p_i} = \max \lbrace {p_{i-1}}, {c_i} + {p_{i-2}} \rbrace$ ($2 \le i \le n$) * računamo naraščajoče po indeksu $i$ * maksimalna količina $p^* = {p_n}$ --- ### Naloga 4 Imamo hlod dolžine $\ell$, ki bi ga radi razžagali na $n$ označenih mestih $0 < {x_1} < {x_2} < \dots < {x_n} < \ell$. Eno rezanje stane toliko, kolikor je dolžina hloda, ki ga režemo. Ko hlod prerežemo, dobimo dva manjša hloda, ki ju režemo naprej. Poiskati želimo zaporedje rezanj z najmanjšo ceno. 1. Reši problem pri podatkih $\ell = 10$ in <i>$(x_i)_{i=1}^4 = (3, 5, 7, 8)$</i>. 2. S pomočjo dinamičnega programiranja reši problem v splošnem. Oceni tudi njegovo časovno zahtevnost. ---- * ${p_{ij}}$ ... najmanjša cena rezanja hloda od ${x_i}$ do ${x_{j+1}}$ * ${x_0} = 0$, ${x_{n+1}} = \ell$ * ${p_{ii}} = 0$ ($0 \le i \le n$) * ${p_{ij}} = {x_{j+1}} - {x_i} + \min \lbrace {p_{i,h-1}} + {p_{hj}} \mid i+1 \le h \le j \rbrace$ ($0 \le i < j \le n$) * računamo leksikografsko po $(j-i, i)$ * najmanjša skupna cena rezanja $p^* = {p_{0n}}$ * časovna zahtevnost: $O(n^3)$ $$ \begin{aligned} p_{01} &= 5-0 &&= 5 \\ p_{12} &= 7-3 &&= 4 \\ p_{23} &= 8-5 &&= 3 \\ p_{34} &= 10-7 &&= 3 \\[1ex] p_{02} &= 7-0 + \min\{0+4, 5+0\} &&= 11 & \text{režemo na $x_1 = 3$} \\ p_{13} &= 8-3 + \min\{0+3, 4+0\} &&= 8 & \text{režemo na $x_2 = 5$} \\ p_{24} &= 10-5 + \min\{0+3, 3+0\} &&= 8 \\[1ex] p_{03} &= 8-0 + \min\{0+8, 5+3, 11+0\} &&= 16 & \text{režemo na $x_1 = 3$ ali $x_2 = 5$} \\ p_{14} &= 10-3 + \min\{0+8, 4+3, 8+0\} &&= 14 & \text{režemo na $x_3 = 7$} \\[1ex] p_{04} &= 10-0 + \min\{0+14, 5+8, 11+3, 16+0\} &&= 23 & \text{režemo na $x_2 = 5$} \end{aligned} $$ ```mermaid graph TD 04[0 - 10: 23] --- 01[0 - 5: 5] 04 --- 24[5 - 10: 8] 01 --- 00[0 - 3] 01 --- 11[3 - 5] 24 --- 23[5 - 8: 3] 24 --- 44[8 - 10] 23 --- 22[5 - 7] 23 --- 33[7 - 8] ``` --- ### Naloga 5 Na voljo imamo kovance z vrednostmi $1 = {v_1} < {v_2} < \cdots < {v_n}$ in vsoto $C$, ki jo želimo izplačati s kovanci. Predpostavljamo, da imamo dovolj velik nabor kovancev. 1. Poišči izplačilo z najmanjšim številom kovancev za $C = 25$, $n = 4$ in <i>$(v_i)_{i=1}^n = (1, 2, 5, 7)$</i>. 2. S pomočjo dinamičnega programiranja reši problem v splošnem. --- ### Naloga 6 Imamo zaporedje $n$ polj, pri čemer je na $i$-tem polju zapisano število ${a_i}$. Na voljo imamo še $\lfloor n/2 \rfloor$ domin, z vsako od katerih lahko pokrijemo dve sosednji polji. Vsaka domina je sestavljena iz dveh delov: na enem je znak $+$, na drugem pa znak $-$. Posamezno polje lahko pokrijemo z le eno domino; če sta pokriti dve sosednji polji, morata biti pokriti z različnima znakoma (bodisi z iste, bodisi z druge domine). Iščemo tako postavitev domin, ki maksimizira vsoto pokritih števil, pomnoženih z znakom na delu domine, ki pokriva število. Pri tem ni potrebno, da uporabimo vse domine. ---- **Primer** dopustnega (ne nujno optimalnega) pokritja: | | [+ | -] | | | [- | +] | [- | +] | | -- | -- | -- | -- | -- | -- | -- | -- | -- | | 6 | 3 | -4 | 2 | -3 | 5 | 9 | 1 | 2 | Vsota tega pokritja je $3 - (-4) - 5 + 9 - 1 + 2 = 12$. Če bi eno od zadnjih dveh domin obrnili (zamenjala bi se znaka), dobljeno pokritje ne bi bilo dopustno, saj bi dve zaporedni polji bili pokriti z enakima znakoma. ---- 1. Zapiši rekurzivne enačbe za reševanje danega problema. Razloži, kaj predstavljajo spremenljivke, v kakšnem vrstnem redu jih računamo, ter kako dobimo optimalno rešitev. **Namig:** posebej obravnavaj dva primera glede na postavitev zadnje domine. 2. Oceni časovno zahtevnost algoritma, ki sledi iz zgoraj zapisanih enačb. 3. S svojim algoritmom poišči optimalno pokritje za zgornji primer.

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