<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=0204_-_Siruri</id>
	<title>0204 - Siruri - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=0204_-_Siruri"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0204_-_Siruri&amp;action=history"/>
	<updated>2026-05-01T05:05:38Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://wiki.universitas.ro/index.php?title=0204_-_Siruri&amp;diff=7647&amp;oldid=prev</id>
		<title>Gabii: Pagină nouă:  = Cerinţa = Se citesc două numere naturale nenule &lt;code&gt;n&lt;/code&gt; și &lt;code&gt;m&lt;/code&gt;. Să se determine toate şirurile cu &lt;code&gt;m&lt;/code&gt; elemente din mulţimea &lt;code&gt;{1,2,..,n}&lt;/code&gt;, ordonate strict crescător, cu proprietatea că oricare două elemente consecutive în şir au diferenţa mai mică sau egală cu cu &lt;code&gt;2&lt;/code&gt;.  = Date de intrare = Fişierul de intrare &lt;code&gt;siruriIN.txt&lt;/code&gt; conţine pe prima linie numerele &lt;code&gt;n&lt;/code&gt; și &lt;code&gt;m&lt;/code&gt;, separate...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0204_-_Siruri&amp;diff=7647&amp;oldid=prev"/>
		<updated>2023-12-04T19:22:14Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă:  = Cerinţa = Se citesc două numere naturale nenule &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt;. Să se determine toate şirurile cu &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt; elemente din mulţimea &amp;lt;code&amp;gt;{1,2,..,n}&amp;lt;/code&amp;gt;, ordonate strict crescător, cu proprietatea că oricare două elemente consecutive în şir au diferenţa mai mică sau egală cu cu &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt;.  = Date de intrare = Fişierul de intrare &amp;lt;code&amp;gt;siruriIN.txt&amp;lt;/code&amp;gt; conţine pe prima linie numerele &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt;, separate...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
= Cerinţa =&lt;br /&gt;
Se citesc două numere naturale nenule &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt;. Să se determine toate şirurile cu &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt; elemente din mulţimea &amp;lt;code&amp;gt;{1,2,..,n}&amp;lt;/code&amp;gt;, ordonate strict crescător, cu proprietatea că oricare două elemente consecutive în şir au diferenţa mai mică sau egală cu cu &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fişierul de intrare &amp;lt;code&amp;gt;siruriIN.txt&amp;lt;/code&amp;gt; conţine pe prima linie numerele &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt;, separate printr-un spațiu.&lt;br /&gt;
&lt;br /&gt;
= Date de ieşire =&lt;br /&gt;
Fişierul de ieşire &amp;lt;code&amp;gt;siruriOUT.txt&amp;lt;/code&amp;gt; va conţine pe fiecare linie câte &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt; valori, separate prin câte un spaţiu, reprezentând elementele unui şir. În cazul în care restricțiile nu sunt îndeplinite, se va afișa mesajul &amp;quot;Nu corespunde restricțiilor&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
= Restricţii şi precizări =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ m ≤ n ≤ 15&amp;lt;/code&amp;gt;&lt;br /&gt;
* şirurile vor fi afişate în ordine lexicografică&lt;br /&gt;
&lt;br /&gt;
= Exemplul 1 =&lt;br /&gt;
&amp;lt;code&amp;gt;siruriIN.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 5 3&lt;br /&gt;
&amp;lt;code&amp;gt;siruriOUT.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 1 2 3 &lt;br /&gt;
 1 2 4 &lt;br /&gt;
 1 3 4 &lt;br /&gt;
 1 3 5 &lt;br /&gt;
 2 3 4 &lt;br /&gt;
 2 3 5 &lt;br /&gt;
 2 4 5 &lt;br /&gt;
 3 4 5 &lt;br /&gt;
&lt;br /&gt;
= Exemplul 2 =&lt;br /&gt;
&amp;lt;code&amp;gt;siruriIN.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 8 9&lt;br /&gt;
&amp;lt;code&amp;gt;siruriOUT.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 Nu corespunde restricțiilor&lt;br /&gt;
&lt;br /&gt;
== Rezolvare ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python3&amp;quot; line=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
def genereaza_siruri(n, m, sir_curent, start):&lt;br /&gt;
    if len(sir_curent) == m:&lt;br /&gt;
        return [sir_curent.copy()]&lt;br /&gt;
&lt;br /&gt;
    siruri = []&lt;br /&gt;
    for i in range(start, n + 1):&lt;br /&gt;
        if not sir_curent or abs(sir_curent[-1] - i) &amp;lt;= 2:&lt;br /&gt;
            sir_curent.append(i)&lt;br /&gt;
            siruri.extend(genereaza_siruri(n, m, sir_curent, i + 1))&lt;br /&gt;
            sir_curent.pop()&lt;br /&gt;
&lt;br /&gt;
    return siruri&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    with open(&amp;quot;siruriIN.txt&amp;quot;, &amp;quot;r&amp;quot;) as fisier_intrare:&lt;br /&gt;
        n, m = map(int, fisier_intrare.readline().split())&lt;br /&gt;
&lt;br /&gt;
    if not (1 &amp;lt;= m &amp;lt;= n &amp;lt;= 15):&lt;br /&gt;
        with open(&amp;quot;siruriOUT.txt&amp;quot;, &amp;quot;w&amp;quot;, encoding=&amp;quot;utf-8&amp;quot;) as fisier_iesire:&lt;br /&gt;
            fisier_iesire.write(&amp;quot;Nu corespunde restricțiilor\n&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    siruri_generate = genereaza_siruri(n, m, [], 1)&lt;br /&gt;
&lt;br /&gt;
    with open(&amp;quot;siruriOUT.txt&amp;quot;, &amp;quot;w&amp;quot;, encoding=&amp;quot;utf-8&amp;quot;) as fisier_iesire:&lt;br /&gt;
        if not siruri_generate:&lt;br /&gt;
            fisier_iesire.write(&amp;quot;Nu corespunde restricțiilor\n&amp;quot;)&lt;br /&gt;
        else:&lt;br /&gt;
            for sir in sorted(siruri_generate):&lt;br /&gt;
                fisier_iesire.write(&amp;quot; &amp;quot;.join(map(str, sir)) + &amp;quot;\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    main()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gabii</name></author>
	</entry>
</feed>