<?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=1489_-_Bile1</id>
	<title>1489 - Bile1 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=1489_-_Bile1"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=1489_-_Bile1&amp;action=history"/>
	<updated>2026-05-01T09:55:26Z</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=1489_-_Bile1&amp;diff=10119&amp;oldid=prev</id>
		<title>Danciu: Pagină nouă:  Algorel a primit un set de &lt;code&gt;n&lt;/code&gt; bile numerotate de la &lt;code&gt;1&lt;/code&gt; la &lt;code&gt;n&lt;/code&gt; pe care trebuie să le pună în trei cutii identice astfel încât în nicio cutie să nu fie două bile numerotate cu numere consecutive.  = Cerința = În câte moduri poate face Algorel acest lucru?  = Date de intrare = Fișierul de intrare &lt;code&gt;bile1.in&lt;/code&gt; conține pe prima linie numărul &lt;code&gt;n&lt;/code&gt;.  = Date de ieșire = Fișierul de ieșire &lt;code&gt;bile1.out&lt;/code&gt; v...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=1489_-_Bile1&amp;diff=10119&amp;oldid=prev"/>
		<updated>2024-06-04T09:07:13Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă:  Algorel a primit un set de &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; bile numerotate de la &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; la &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; pe care trebuie să le pună în trei cutii identice astfel încât în nicio cutie să nu fie două bile numerotate cu numere consecutive.  = Cerința = În câte moduri poate face Algorel acest lucru?  = Date de intrare = Fișierul de intrare &amp;lt;code&amp;gt;bile1.in&amp;lt;/code&amp;gt; conține pe prima linie numărul &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;.  = Date de ieșire = Fișierul de ieșire &amp;lt;code&amp;gt;bile1.out&amp;lt;/code&amp;gt; v...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
Algorel a primit un set de &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; bile numerotate de la &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; la &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; pe care trebuie să le pună în trei cutii identice astfel încât în nicio cutie să nu fie două bile numerotate cu numere consecutive.&lt;br /&gt;
&lt;br /&gt;
= Cerința =&lt;br /&gt;
În câte moduri poate face Algorel acest lucru?&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fișierul de intrare &amp;lt;code&amp;gt;bile1.in&amp;lt;/code&amp;gt; conține pe prima linie numărul &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Date de ieșire =&lt;br /&gt;
Fișierul de ieșire &amp;lt;code&amp;gt;bile1.out&amp;lt;/code&amp;gt; va conține pe prima linie numărul de moduri de distribuire a bilelor.&lt;br /&gt;
&lt;br /&gt;
= Restricții și precizări =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;n ≤ 300&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Exemplu: =&lt;br /&gt;
&amp;lt;code&amp;gt;bile1.in&amp;lt;/code&amp;gt;&lt;br /&gt;
 4&lt;br /&gt;
&amp;lt;code&amp;gt;bile1.out&amp;lt;/code&amp;gt;&lt;br /&gt;
 24&lt;br /&gt;
&lt;br /&gt;
== Rezolvare ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python3&amp;quot;&amp;gt;&lt;br /&gt;
MOD = 1000000007  &lt;br /&gt;
&lt;br /&gt;
def count_ball_distributions(n):&lt;br /&gt;
    dp = [[0 for _ in range(4)] for _ in range(n + 1)]&lt;br /&gt;
&lt;br /&gt;
    for i in range(1, n + 1):&lt;br /&gt;
        dp[i][1] = 3&lt;br /&gt;
&lt;br /&gt;
    for i in range(2, n + 1):&lt;br /&gt;
        for j in range(1, 4):&lt;br /&gt;
            dp[i][j] = 0&lt;br /&gt;
&lt;br /&gt;
            if j &amp;lt; 3:&lt;br /&gt;
                dp[i][j] += dp[i - 1][j - 1] * 3&lt;br /&gt;
                dp[i][j] += dp[i - 2][1] * 3&lt;br /&gt;
&lt;br /&gt;
            if j &amp;lt;= dp[i - 1][0]:&lt;br /&gt;
                dp[i][j] += dp[i - 1][j - 1]&lt;br /&gt;
&lt;br /&gt;
    return dp[n][1] % MOD&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    with open(&amp;quot;bile1.in&amp;quot;, &amp;quot;r&amp;quot;) as input_file:&lt;br /&gt;
        n = int(input_file.readline())&lt;br /&gt;
&lt;br /&gt;
    ball_distributions_count = count_ball_distributions(n)&lt;br /&gt;
&lt;br /&gt;
    with open(&amp;quot;bile1.out&amp;quot;, &amp;quot;w&amp;quot;) as output_file:&lt;br /&gt;
        output_file.write(str(ball_distributions_count))&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>Danciu</name></author>
	</entry>
</feed>