﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-I believe-随笔分类-组合数学</title><link>http://www.cppblog.com/luyulaile/category/10537.html</link><description>I  can</description><language>zh-cn</language><lastBuildDate>Fri, 13 Apr 2012 10:35:44 GMT</lastBuildDate><pubDate>Fri, 13 Apr 2012 10:35:44 GMT</pubDate><ttl>60</ttl><item><title>费马小定理</title><link>http://www.cppblog.com/luyulaile/archive/2012/04/11/170856.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Tue, 10 Apr 2012 23:16:00 GMT</pubDate><guid>http://www.cppblog.com/luyulaile/archive/2012/04/11/170856.html</guid><wfw:comment>http://www.cppblog.com/luyulaile/comments/170856.html</wfw:comment><comments>http://www.cppblog.com/luyulaile/archive/2012/04/11/170856.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luyulaile/comments/commentRss/170856.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luyulaile/services/trackbacks/170856.html</trackback:ping><description><![CDATA[<h2>&nbsp; &nbsp;&nbsp;<span style="font-family: arial, 宋体, sans-serif; font-size: 14px; font-weight: normal; line-height: 25px; background-color: #ffffff; ">假如p是质数，且(a,p)=1，那么 a^(p-1) &#8801;1（mod p） <br />&nbsp; &nbsp; &nbsp; &nbsp;假如p是质数，且a,p互质，那么 a的(p-1)次方除以p的余数恒等于1</span>&nbsp;<br />历史</h2><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　与费马小定理相关的有一个</span><a target="_blank" href="http://baike.baidu.com/view/61891.htm" style="color: #136ec2; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">中国</a><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">猜想，这个猜想是中国数学家提出来的，其内容为：当且仅当2^(p-1）&#8801;1(mod p），p是一个质数。</span><div style="height: 14px; line-height: 14px; font-size: 12px; overflow-x: hidden; overflow-y: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　假如p是一个质数的话，则2^(p-1）&#8801;1(mod p）成立（这是费马小定理的一个特殊情况）是对的。但反过来，假如2^(p-1）&#8801;1(mod p）成立那么p是一个质数是不成立的（比如341符合上述条件但不是一个质数）。因此整个来说这个猜想是错误的。一般认为中国数学家在费马前2000年的时候就已经认识中国猜测了，但也有人认为实际上中国猜测是1872年提出的，认为它早就为人所知是出于一个误解。</span><div style="height: 30px; line-height: 30px; overflow-x: hidden; overflow-y: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><h2><span editable-title"="" data-edit-id="263807:263807:2" style="font-size: 12px; float: right; display: block; margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #3366cc; font-weight: normal; "><a href="http://baike.baidu.com/view/263807.htm#" style="color: #136ec2; height: 15px; line-height: 16px; background-image: url(http://img.baidu.com/img/baike/bk-split-icons.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; display: block; width: 52px; padding-left: 18px; background-position: 0% -108px; background-repeat: no-repeat no-repeat; ">编辑本段</a></span><a name="2" style="text-decoration: underline; color: rgb(19, 110, 194); "></a><a name="sub263807_2" style="text-decoration: underline; color: rgb(19, 110, 194); "></a>证明</h2><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　</span><strong style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">一、准备知识：</strong><div style="height: 14px; line-height: 14px; font-size: 12px; overflow-x: hidden; overflow-y: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　</span><strong style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">引理1．<a target="_blank" href="http://baike.baidu.com/view/1758580.htm" style="color: #136ec2; ">剩余系</a>定理2</strong><div style="height: 14px; line-height: 14px; font-size: 12px; overflow-x: hidden; overflow-y: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　若a,b,c为任意3个整数，m为正整数，且（m,c)=1，则当ac&#8801;bc(mod m）时，有a&#8801;b(mod m)</span><div style="height: 14px; line-height: 14px; font-size: 12px; overflow-x: hidden; overflow-y: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　证明：ac&#8801;bc(mod m）可得ac&#8211;bc&#8801;0(mod m）可得（a-b)c&#8801;0(mod m）因为（m,c)=1即m,c互质，c可以约去，a&#8211;b&#8801;0(mod m）可得a&#8801;b(mod m)</span><div style="height: 14px; line-height: 14px; font-size: 12px; overflow-x: hidden; overflow-y: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　</span><strong style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">引理2．剩余系定理5</strong><div style="height: 14px; line-height: 14px; font-size: 12px; overflow-x: hidden; overflow-y: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　若m为整数且m&gt;1,a[1],a[2],a[3],a[4]，&#8230;a[m]为m个整数，若在这m个数中任取2个整数对m不同余，则这m个整数对m构成完全剩余系。</span><div style="height: 14px; line-height: 14px; font-size: 12px; overflow-x: hidden; overflow-y: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　证明：构造m的完全剩余系（0,1,2，&#8230;m-1），所有的整数必然这些整数中的1个对模m同余。取r[1]=0,r[2]=1,r[3]=2,r[4]=3，&#8230;r=i-1,1&lt;i&lt;=m。令（1）：a[1]&#8801;r[1](mod m),a[2]&#8801;r[2](mod m),a&#8801;r(mod m）（顺序可以不同），因为只有在这种情况下才能保证集合{a1,a2,a3,a4，&#8230;am}中的任意2个数不同余，否则必然有2个数同余。由式（1）自然得到集合{a1,a2,a3,a4，&#8230;am}对m构成完全剩余系。</span><div style="height: 14px; line-height: 14px; font-size: 12px; overflow-x: hidden; overflow-y: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　</span><strong style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">引理3．剩余系定理7</strong><div style="height: 14px; line-height: 14px; font-size: 12px; overflow-x: hidden; overflow-y: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　设m是一个整数，且m&gt;1，b是一个整数且（m,b)=1。如果a1,a2,a3,a4，&#8230;am是模m的一个完全剩余系，则ba[1],ba[2],ba[3],ba[4]，&#8230;ba[m]也构成模m的一个完全剩余系。</span><div style="height: 14px; line-height: 14px; font-size: 12px; overflow-x: hidden; overflow-y: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　证明：若存在2个整数ba和ba[j]同余即ba&#8801;ba[j](mod m），根据引理1则有a&#8801;a[j](mod m）。根据完全剩余系的定义和引理4（完全剩余系中任意2个数之间不同余，易证明）可知这是不可能的，因此不存在2个整数ba和ba[j]同余。由引理5可知ba[1],ba[2],ba[3],ba[4]，&#8230;ba[m]构成模m的一个完全剩余系。</span><div style="height: 14px; line-height: 14px; font-size: 12px; overflow-x: hidden; overflow-y: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　</span><strong style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">引理4．<a target="_blank" href="http://baike.baidu.com/view/79282.htm" style="color: #136ec2; ">同余</a>定理6</strong><div style="height: 14px; line-height: 14px; font-size: 12px; overflow-x: hidden; overflow-y: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　如果a,b,c,d是四个整数，且a&#8801;b(mod m),c&#8801;d(mod m），则有ac&#8801;bd(mod m)</span><div style="height: 14px; line-height: 14px; font-size: 12px; overflow-x: hidden; overflow-y: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　证明：由题设得ac&#8801;bc(mod m),bc&#8801;bd(mod m），由模运算的传递性可得ac&#8801;bd(mod m)</span><div style="height: 14px; line-height: 14px; font-size: 12px; overflow-x: hidden; overflow-y: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　</span><strong style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">二、证明过程：</strong><div style="height: 14px; line-height: 14px; font-size: 12px; overflow-x: hidden; overflow-y: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　构造</span><a target="_blank" href="http://baike.baidu.com/view/1767.htm" style="color: #136ec2; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">素数</a><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">p的完全剩余系P={1,2,3,4&#8230;（p-1)}，因为（a,p)=1，由引理3可得A={a,2a,3a,4a，&#8230;（p-1)a}也是p的一个完全剩余系。令W=1*2*3*4&#8230;*(p-1），显然W&#8801;W(mod p）。令Y=a*2a*3a*4a*&#8230;（p-1)a，因为{a,2a,3a,4a，&#8230;（p-1)a}是p的完全剩余系，由引理2以及引理4可得a*2a*3a*&#8230;（p-1)a&#8801;1*2*3*&#8230;（p-1)(mod p）即W*a^(p-1）&#8801;W(modp）。易知（W,p)=1，由引理1可知a^(p-1）&#8801;1(modp）</span>&nbsp;<img src ="http://www.cppblog.com/luyulaile/aggbug/170856.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luyulaile/" target="_blank">luis</a> 2012-04-11 07:16 <a href="http://www.cppblog.com/luyulaile/archive/2012/04/11/170856.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>欧拉定理证明 &amp;&amp; 欧拉公式</title><link>http://www.cppblog.com/luyulaile/archive/2012/04/11/170855.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Tue, 10 Apr 2012 23:11:00 GMT</pubDate><guid>http://www.cppblog.com/luyulaile/archive/2012/04/11/170855.html</guid><wfw:comment>http://www.cppblog.com/luyulaile/comments/170855.html</wfw:comment><comments>http://www.cppblog.com/luyulaile/archive/2012/04/11/170855.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luyulaile/comments/commentRss/170855.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luyulaile/services/trackbacks/170855.html</trackback:ping><description><![CDATA[<span style="line-height: 18px; color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; font-weight: bold; ">源地址：</span>
<a href="http://www.cppblog.com/zoyi-zhang/articles/43456.html">http://www.cppblog.com/zoyi-zhang/articles/43456.html</a>&nbsp;<br /><span style="line-height: 18px; color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; font-weight: bold; ">欧拉函数 ：</span><br style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; " /><span style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; background-color: #ffffff; ">欧拉函数是数论中很重要的一个函数，欧拉函数是指：对于一个正整数 n ，小于 n 且和 n 互质的正整数（包括 1）的个数，记作 &#966;(n) 。&nbsp;</span><br style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; " /><br style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; " /><span style="line-height: 18px; color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; font-weight: bold; ">完全余数集合：</span><br style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; " /><span style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; background-color: #ffffff; ">定义小于 n 且和 n 互质的数构成的集合为 Zn ，称呼这个集合为 n 的完全余数集合。 显然 |Zn| ＝&#966;(n) 。</span><br style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; " /><br style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; " /><span style="line-height: 18px; color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; font-weight: bold; ">有关性质：</span><br style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; " /><span style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; background-color: #ffffff; ">对于素数 p ，&#966;(p) = p -1 。</span><br style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; " /><span style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; background-color: #ffffff; ">对于两个不同素数 p， q ，它们的乘积 n = p * q 满足 &#966;(n) = (p -1) * (q -1)&nbsp; 。</span><br style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; " /><span style="line-height: 18px; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; color: #ff0000; ">这是因为 Zn = {1, 2, 3,&nbsp; ... , n - 1} - {p, 2p, ... , (q - 1) * p} - {q, 2q, ... , (p - 1) * q} ， 则 &#966;(n) = (n - 1) - (q - 1) - (p - 1) = (p -1) * (q -1)&nbsp; ＝</span><span style="line-height: 18px; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; color: #ff0000; ">&#966;(p) *&nbsp;</span><span style="line-height: 18px; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; color: #ff0000; ">&#966;(q)</span><span style="line-height: 18px; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; color: #ff0000; ">&nbsp;。</span><br style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; " /><br style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; " /><span style="line-height: 18px; color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; font-weight: bold; ">欧拉定理 ：</span><br style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; " /><span style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; background-color: #ffffff; ">对于互质的正整数 a 和 n ，有&nbsp;</span><span style="line-height: 18px; color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; font-weight: bold; ">a</span><sup style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; font-weight: bold; ">&#966;(n)</sup><span style="line-height: 18px; color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; font-weight: bold; ">&nbsp; &#8801; 1 mod n</span><span style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; background-color: #ffffff; ">&nbsp; 。</span><br style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; " /><br style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; " /><span style="line-height: 18px; color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; font-weight: bold; ">证明：<br /></span><span style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; background-color: #ffffff; ">( 1 ) 令&nbsp;</span>Zn = {x<sub>1</sub>, x<sub>2</sub>, ..., x<sub>&#966;(n)</sub>}&nbsp;<span style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; background-color: #ffffff; ">，&nbsp;</span>S&nbsp;= {a * x<sub>1</sub>&nbsp;mod n, a * x<sub>2</sub>&nbsp;mod n, ... , a * x<sub>&#966;(n)</sub>&nbsp;mod n}&nbsp;<span style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; background-color: #ffffff; ">，</span><br style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; " /><span style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; background-color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 则 Zn = S 。</span><br style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; " /><span style="line-height: 18px; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; color: #ff0000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#9312; 因为 a 与 n 互质，</span>&nbsp;x<sub>i</sub>&nbsp;<span style="line-height: 18px; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; color: #ff0000; ">(1 &#8804; i &#8804; &#966;(n))&nbsp;</span><span style="line-height: 18px; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; color: #ff0000; ">与 n 互质， 所以 a *&nbsp;</span>x<sub>i</sub><span style="line-height: 18px; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; color: #ff0000; ">&nbsp; 与 n 互质，所以 a *&nbsp;</span>x<sub>i</sub><span style="line-height: 18px; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; color: #ff0000; ">&nbsp; mod n &#8712; Zn 。</span><br style="font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; color: #ff0000; " /><span style="line-height: 18px; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; color: #ff0000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#9313; 若 i &#8800; j ， 那么&nbsp;</span>x<sub style="font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; color: #ff0000; ">i</sub><span style="line-height: 18px; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; color: #ff0000; ">&nbsp;&#8800;&nbsp;</span>x<sub style="font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; color: #ff0000; ">j</sub><span style="line-height: 18px; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; color: #ff0000; ">，且由 a, n互质可得&nbsp;</span>a * x<sub style="font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; color: #ff0000; ">i</sub><span style="line-height: 18px; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; color: #ff0000; ">&nbsp;mod n &#8800;&nbsp;</span>a * x<sub style="font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; color: #ff0000; ">j</sub><span style="line-height: 18px; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; color: #ff0000; ">&nbsp;mod n （消去律）。</span><br style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; " /><br style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; " /><span style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; background-color: #ffffff; ">( 2 )&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>a<sup>&#966;(n)&nbsp;</sup>*&nbsp;x<sub>1&nbsp;</sub>*&nbsp;x<sub>2</sub>&nbsp;*... *&nbsp;x<sub>&#966;(n)</sub>&nbsp;mod n&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; background-color: #ffffff; ">&#8801;</span>&nbsp;(a * x<sub>1</sub>) * (a * x<sub>2</sub>) * ... * (a * x<sub>&#966;(n)</sub>)&nbsp;mod n<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; background-color: #ffffff; ">&#8801;</span>&nbsp;(a * x<sub>1</sub>&nbsp;mod n) * (a * x<sub>2&nbsp;</sub>mod n) * ... * (a * x<sub>&#966;(n)</sub>&nbsp;mod n)&nbsp;mod n<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px; background-color: #ffffff; ">&#8801;</span>&nbsp;&nbsp;x<sub>1&nbsp;</sub>*&nbsp;x<sub>2&nbsp;</sub>* ... *&nbsp;x<sub>&#966;(n)&nbsp;</sub>mod n<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 对比等式的左右两端，因为&nbsp;x<sub>i</sub><span style="line-height: 24px; ">&nbsp; (1 &#8804; i &#8804; &#966;(n)) 与 n 互质，所以&nbsp;</span>a<sup>&#966;(n)</sup>&nbsp;&nbsp;&#8801;&nbsp; 1 mod n （消去律）。<br />注：<br />消去律：如果 gcd(c,p) = 1 ，则 ac &#8801; bc mod p &#8658; a &#8801; b mod p 。<br /><br /><span style="line-height: 24px; font-weight: bold; ">费马定理 ：</span><br />若正整数 a 与素数 p 互质，则有&nbsp;<span style="line-height: 24px; font-weight: bold; ">a</span><sup style="font-weight: bold; ">p - 1</sup><span style="line-height: 24px; font-weight: bold; ">&nbsp;&#8801; 1 mod p</span>&nbsp;。<br /><span style="line-height: 24px; color: #ff0000; ">证明这个定理非常简单，由于 &#966;(p) = p -1，代入欧拉定理即可证明。</span><br style="color: #ff0000; " />*****************************************************************************<br /><span style="line-height: 24px; font-weight: bold; ">补充：欧拉函数公式<br /></span><div><h2>( 1 ) p<sup>k</sup>&nbsp;的欧拉函数</h2><p>对于给定的一个素数 p ， &#966;(p) = p -1。则对于正整数 n = p<sup>k</sup>&nbsp;，</p><pre><strong> </strong><span style="font-weight: bold; ">&#966;</span><strong>(n) = p<sup>k</sup> - p<sup>k -1</sup><br />  </strong><br /><span style="color: #ff0000; ">证明：</span><br style="color: #ff0000; " /><span style="color: #ff0000; "> 小于 p</span><sup style="color: #ff0000; ">k</sup><span style="color: #ff0000; "> 的正整数个数为 p</span><sup style="color: #ff0000; ">k</sup><span style="color: #ff0000; "> - 1个，其中</span><br style="color: #ff0000; " /><span style="color: #ff0000; "> 和 p</span><sup style="color: #ff0000; ">k</sup><span style="color: #ff0000; "> 不互质的正整数有</span><strong style="color: #ff0000; ">{p * 1,p * 2,...,p * (p<sup>k - 1</sup>-1)}</strong><span style="color: #ff0000; "> 共计 </span><strong style="color: #ff0000; ">p<sup>k - 1</sup> - 1</strong><span style="color: #ff0000; "> 个</span><br style="color: #ff0000; " /><span style="color: #ff0000; "> 所以 &#966;(n) = p</span><sup style="color: #ff0000; ">k</sup><span style="color: #ff0000; "> - 1 - (p</span><sup style="color: #ff0000; ">k - 1</sup><span style="color: #ff0000; "> - 1) = p</span><sup style="color: #ff0000; ">k</sup><span style="color: #ff0000; "> - p</span><sup style="color: #ff0000; ">k - 1</sup><span style="color: #ff0000; "> 。</span></pre><h2>( 2 ) p * q 的欧拉函数</h2><p>假设 p, q是两个互质的正整数，则 p * q 的欧拉函数为</p><p style="font-weight: bold; ">&#966;(p * q) = &#966;(p) * &#966;(q) ， gcd(p, q) = 1 。</p><pre><span style="color: #ff0000; ">证明：</span><br style="color: #ff0000; " /><span style="color: #ff0000; "> 令 n = p * q ， gcd(p,q) = 1</span><br style="color: #ff0000; " /><span style="color: #ff0000; "> 根据中国余数定理，有</span><br style="color: #ff0000; " /><span style="color: #ff0000; "> Zn 和 Zp &#215; Zq 之间存在一一映射<br /><span style="font-weight: bold; ">（我的想法是： a </span></span><span style="font-weight: bold; color: #ff0000; ">&#8712; Zp ， b &#8712; Zq &#8660; b * p + a * q &#8712; Zn 。</span><span style="color: #ff0000; "><span style="font-weight: bold; ">）</span><br /></span><span style="color: #ff0000; "> 所以 n 的完全余数集合的元素个数等于集合 Zp &#215; Zq 的元素个数。</span><br style="color: #ff0000; " /><span style="color: #ff0000; "> 而后者的元素个数为 &#966;(p) * &#966;(q) ，所以有</span><br style="color: #ff0000; " /><span style="color: #ff0000; "> &#966;(p * q) = &#966;(p) * &#966;(q) 。</span><br /></pre><h2>( 3 ) 任意正整数的欧拉函数</h2><p>任意一个整数 n 都可以表示为其素因子的乘积为：</p><pre>    <span style="font-weight: bold; ">  I</span><br /><span style="font-weight: bold; "> n = &#8719;  p</span><sub style="font-weight: bold; ">i</sub><sup style="font-weight: bold; ">k<sub>i</sub></sup> (I 为 n 的素因子的个数)<br />     <span style="font-weight: bold; ">i=1</span><br /></pre><p>根据前面两个结论，很容易得出它的欧拉函数为：</p><pre><strong><br />         I                      I<br /> &#934;(n) = &#8719;  p<sub>i</sub><sup>k<sub>i </sub>-1</sup>(p<sub>i </sub>-1) = n </strong><strong><strong>&#8719;</strong></strong><strong> (1 - 1 / pi)<br />        i=1                   </strong><strong><strong> i=1</strong></strong></pre><p>对于任意 n &gt; 2，<span style="line-height: 24px; font-weight: bold; ">2 | &#934;(n</span>) ,因为必存在&nbsp;&nbsp;<strong><strong>p<sub>i&nbsp;</sub>-1&nbsp;</strong></strong>是偶数。</p></div><img src ="http://www.cppblog.com/luyulaile/aggbug/170855.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luyulaile/" target="_blank">luis</a> 2012-04-11 07:11 <a href="http://www.cppblog.com/luyulaile/archive/2012/04/11/170855.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>joj 2296 Boxs 组合数学</title><link>http://www.cppblog.com/luyulaile/archive/2009/07/21/90706.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Tue, 21 Jul 2009 04:21:00 GMT</pubDate><guid>http://www.cppblog.com/luyulaile/archive/2009/07/21/90706.html</guid><wfw:comment>http://www.cppblog.com/luyulaile/comments/90706.html</wfw:comment><comments>http://www.cppblog.com/luyulaile/archive/2009/07/21/90706.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luyulaile/comments/commentRss/90706.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luyulaile/services/trackbacks/90706.html</trackback:ping><description><![CDATA[<p>题意是N个不同的盒子，A个完全相同的红球，B个完全相同的篮球，现在把球往盒里装，球可以不全部装到盒里，盒可以为空，问方法数。</p>
<p>其实就是把A个红球，B个篮球分成n+1堆（除n堆外还有一堆就是没有放入盒中的）。<br>思路很重要，<br>我的思路是由于A球，B球不同色，可以看成两个独立事件，则结果为count(A)*count(B),<br>其中count(A)表示A的放法，<br>则利用隔板法(或者多重集的r组合)：count(A)=C(n+1+A-1,n+1-1&nbsp;&nbsp; ),利用pascal公式c(n,m)=c(n-1,m)+c(n-1,m-1)来求该式;</p>
<p>还有一个注意点当且仅当n=20,a= 15 ,b=15时会超出long long 范围。所以特殊处理<br></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img id=Code_Closed_Image_121005 onclick="this.style.display='none'; Code_Closed_Text_121005.style.display='none'; Code_Open_Image_121005.style.display='inline'; Code_Open_Text_121005.style.display='inline';" height=16 src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" width=11 align=top><img id=Code_Open_Image_121005 style="DISPLAY: none" onclick="this.style.display='none'; Code_Open_Text_121005.style.display='none'; Code_Closed_Image_121005.style.display='inline'; Code_Closed_Text_121005.style.display='inline';" height=16 src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width=11 align=top><span id=Code_Closed_Text_121005 style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">点"+"展开</span><span id=Code_Open_Text_121005 style="DISPLAY: none"><br><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstdlib</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000">&nbsp;std;<br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;num[</span><span style="COLOR: #000000">40</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">40</span><span style="COLOR: #000000">];&nbsp;&nbsp;<br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;fun(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;m)<br>{<br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(n</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(num[n][m]</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;num[n][m];<br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">if(m==0||m==n)<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;return&nbsp;1;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(num[n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][m]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num[n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][m]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">fun(n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,m);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(num[n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][m</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num[n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][m</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">fun(n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,m</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;num[n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][m]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">num[n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][m</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">];<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;a,b,n,s;<br>&nbsp;&nbsp;memset(num,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(num));<br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(s</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;s</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">41</span><span style="COLOR: #000000">;s</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">????&#232;??????&#168;??&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;{&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num[s][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num[s][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">s;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num[s][s</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">s;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num[s][s]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">b)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(n</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">20</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">15</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">b</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">15</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">10549134770590785600</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">fun(a</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">n,n)</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">fun(b</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">n,n)</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;}<br><br></span></span></div>
代码点+会自动展开
<img src ="http://www.cppblog.com/luyulaile/aggbug/90706.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luyulaile/" target="_blank">luis</a> 2009-07-21 12:21 <a href="http://www.cppblog.com/luyulaile/archive/2009/07/21/90706.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>joj 1206 Word Index 利用组合数学性质 推荐</title><link>http://www.cppblog.com/luyulaile/archive/2009/07/18/90406.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Sat, 18 Jul 2009 02:08:00 GMT</pubDate><guid>http://www.cppblog.com/luyulaile/archive/2009/07/18/90406.html</guid><wfw:comment>http://www.cppblog.com/luyulaile/comments/90406.html</wfw:comment><comments>http://www.cppblog.com/luyulaile/archive/2009/07/18/90406.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luyulaile/comments/commentRss/90406.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luyulaile/services/trackbacks/90406.html</trackback:ping><description><![CDATA[<div class=prob_text>
<p>Encoding schemes are often used in situations requiring encryption or information storage/transmission economy. Here, we develop a simple encoding scheme that encodes particular types of words with five or fewer (lower case) letters as integers.
<p>
<p>Consider the English alphabet {<tt>a,b,c,...,z</tt>}. Using this alphabet, a set of <em>valid</em> words are to be formed that are in a strict lexicographic order. In this set of <em>valid</em> words, the successive letters of a word are in a strictly ascending order; that is, later letters in a valid word are always <em>after</em> previous letters with respect to their positions in the alphabet list {<tt>a,b,c,...,z</tt>}. For example,
<p>
<p><tt>abc aep gwz</tt>
<p>
<p>
<p>are all <em>valid</em> three-letter words, whereas
<p>
<p><tt>aab are cat</tt>
<p>
<p>
<p>are not.
<p>
<p>For each <em>valid</em> word associate an integer which gives the position of the word in the alphabetized list of words. That is:
<p>
<pre>    a -&gt; 1
b -&gt; 2
.
.
z -&gt; 26
ab -&gt; 27
ac -&gt; 28
.
.
az -&gt; 51
bc -&gt; 52
.
.
vwxyz -&gt; 83681</pre>
<p>Your program is to read a series of input lines. Each input line will have a single word on it, that will be from one to five letters long. For each word read, if the word is <em>invalid</em> give the number 0. If the word read is <em>valid</em>, give the word's position index in the above alphabetical list.
<h3>Input</h3>
<p>The input consists of a series of single words, one per line. The words are at least one letter long and no more that five letters. Only the lower case alphabetic {<tt>a,b,...,z</tt>} characters will be used as input. The first letter of a word will appear as the first character on an input line.
<p>
<p>The input will be terminated by end-of-file.
<h3>Output</h3>
<p>The output is a single integer, greater than or equal to zero (0) and less than or equal 83681. The first digit of an output value should be the first character on a line. There is one line of output for each input line.
<h3>Sample Input</h3>
<p>
<pre>z
a
cat
vwxyz</pre>
<h3>Sample Output</h3>
<p>
<pre>26
1
0
83681</pre>
<p>&#160;</p>
利用组合数学定理<br>{1,2,3,--,n}的r组合a1,a2,--,ar出现在{1，2，--，n}的r组合的字典序中的位置号如下：<br><br>C(n,r)-C(n-a1,r)-C(n-a2,r-1)-------C(n-ar-1，2)-C(n-ar,1):证明略；<br><br>组合数C(n,r)计算利用pascal公式。C(n+1,k)=C(n,k-1)+C(n,k)</div>
<img src ="http://www.cppblog.com/luyulaile/aggbug/90406.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luyulaile/" target="_blank">luis</a> 2009-07-18 10:08 <a href="http://www.cppblog.com/luyulaile/archive/2009/07/18/90406.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>joj 1026 动态规划，生成函数及改进</title><link>http://www.cppblog.com/luyulaile/archive/2009/06/27/88628.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Sat, 27 Jun 2009 02:44:00 GMT</pubDate><guid>http://www.cppblog.com/luyulaile/archive/2009/06/27/88628.html</guid><wfw:comment>http://www.cppblog.com/luyulaile/comments/88628.html</wfw:comment><comments>http://www.cppblog.com/luyulaile/archive/2009/06/27/88628.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luyulaile/comments/commentRss/88628.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luyulaile/services/trackbacks/88628.html</trackback:ping><description><![CDATA[<div class=prob_text>
<p>One curious child has a set of N little bricks. From these bricks he builds different staircases. Staircase consists of steps of different sizes in a strictly descending order. It is not allowed for staircase to have steps equal sizes. Every staircase consists of at least two steps and each step contains at least one brick. Picture gives examples of staircase for N=11 and N=5:</p>
<p align=center><img height=163 src="http://acm.jlu.edu.cn/joj/images/problems/1026.gif" width=623> </p>
<p align=left>Your task is to write a program that reads from input numbers N and writes to output numbers Q - amount of different staircases that can be built from exactly N bricks.</p>
<br>
<h3>Input</h3>
Numbers N, one on each line. You can assume N is between 3 and 500, both inclusive. A number 0 indicates the end of input.
<p>&#160;</p>
<p>&#160;</p>
<br>
<h3>Output</h3>
Numbers Q, one on each line.
<p>&#160;</p>
<br>
<h3>Sample Input</h3>
<pre>3
5
0
</pre>
<h3>Sample Output</h3>
<pre>1
2
</pre>
方法1，动态规划<br><br>#include&lt;iostream&gt;<br>#include&lt;cstdlib&gt;<br>using namespace std;<br>&nbsp; int main()<br>&nbsp; {<br>&nbsp; freopen("s.txt","r",stdin);<br>&nbsp; freopen("key.txt","w",stdout);<br>&nbsp; double f[501][501]={0};<br>&nbsp; double s;<br>&nbsp; int i,j,k,n;<br>&nbsp; for(i=3;i&lt;=500;i++)<br>&nbsp; for(j=1;j&lt;=(i-1)/2;j++)<br>&nbsp;&nbsp;&nbsp; f[i][j]=1;<br>&nbsp; for(i=3;i&lt;=500;i++)<br>&nbsp;&nbsp;&nbsp; for(j=1;j&lt;=(i-1)/2;j++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;for(k=j+1;k&lt;=(i-j-1)/2;k++)<br>&nbsp;&nbsp; f[i][j]=f[i-j][k];&nbsp;<br>&nbsp;}<br>&nbsp;&nbsp;&nbsp; while(scanf("%d",&amp;n),n) { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s=0; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(i=1;i&lt;=(n-1)/2;i++) s+=f[n][i]; //f[n]=f[n][1]+f[n][2]+-----+f[n][floor((i-1)/2)]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%.0f\n",s); <br>&nbsp;&nbsp;&nbsp; } <br>&nbsp; //system("PAUSE");<br>&nbsp; return&nbsp;&nbsp; 0;<br>&nbsp; }<br>更妙的方法：生成函数法<br>计算(1+x)(1+x^2)(1+x^3)-----,x^n的系数即为所求<br>int i,j;<br>double ans[510]={1,1};//已经把ans[1]和ans[0]赋为1了，其余为0<br>&nbsp;for(i=2;i&lt;=500;i++) {&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(j=500;j&gt;=0;j--) {&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(i+j&lt;=500) ans[i+j]+=ans[j]; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp; <br>&nbsp;&nbsp;&nbsp; }&nbsp; <br><br>先计算(1+x)(1+x^2)<br>再计算(1+x)(1+x^2)&nbsp;&nbsp; *(1+x^3)<br></div>
<img src ="http://www.cppblog.com/luyulaile/aggbug/88628.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luyulaile/" target="_blank">luis</a> 2009-06-27 10:44 <a href="http://www.cppblog.com/luyulaile/archive/2009/06/27/88628.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>&lt;转帖&gt;  joj 1978  </title><link>http://www.cppblog.com/luyulaile/archive/2009/05/12/82667.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Tue, 12 May 2009 03:42:00 GMT</pubDate><guid>http://www.cppblog.com/luyulaile/archive/2009/05/12/82667.html</guid><wfw:comment>http://www.cppblog.com/luyulaile/comments/82667.html</wfw:comment><comments>http://www.cppblog.com/luyulaile/archive/2009/05/12/82667.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luyulaile/comments/commentRss/82667.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luyulaile/services/trackbacks/82667.html</trackback:ping><description><![CDATA[<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstdio</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;b[</span><span style="COLOR: #000000">51</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">51</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">50</span><span style="COLOR: #000000">],&nbsp;N;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;add&nbsp;(&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;j&nbsp;)<br><img id=Codehighlighter1_86_332_Open_Image onclick="this.style.display='none'; Codehighlighter1_86_332_Open_Text.style.display='none'; Codehighlighter1_86_332_Closed_Image.style.display='inline'; Codehighlighter1_86_332_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_86_332_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_86_332_Closed_Text.style.display='none'; Codehighlighter1_86_332_Open_Image.style.display='inline'; Codehighlighter1_86_332_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_86_332_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_86_332_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;k;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(&nbsp;k&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;k&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">50</span><span style="COLOR: #000000">;&nbsp;k&nbsp;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b[i][j][k]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;b[i&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][k]&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;b[i&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j][k]&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;j;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;c&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;t;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(&nbsp;k&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;k&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">50</span><span style="COLOR: #000000">;&nbsp;k&nbsp;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)<br><img id=Codehighlighter1_247_330_Open_Image onclick="this.style.display='none'; Codehighlighter1_247_330_Open_Text.style.display='none'; Codehighlighter1_247_330_Closed_Image.style.display='inline'; Codehighlighter1_247_330_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_247_330_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_247_330_Closed_Text.style.display='none'; Codehighlighter1_247_330_Open_Image.style.display='inline'; Codehighlighter1_247_330_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_247_330_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_247_330_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;b[i][j][k]&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;c;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;t&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b[i][j][k]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;t&nbsp;</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;dp&nbsp;()<br><img id=Codehighlighter1_346_608_Open_Image onclick="this.style.display='none'; Codehighlighter1_346_608_Open_Text.style.display='none'; Codehighlighter1_346_608_Closed_Image.style.display='inline'; Codehighlighter1_346_608_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_346_608_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_346_608_Closed_Text.style.display='none'; Codehighlighter1_346_608_Open_Image.style.display='inline'; Codehighlighter1_346_608_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_346_608_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_346_608_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;memset&nbsp;(&nbsp;b,&nbsp;</span><span style="COLOR: #000000">0x00</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">&nbsp;(&nbsp;b&nbsp;)&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,&nbsp;j;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(&nbsp;i&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;i&nbsp;</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">50</span><span style="COLOR: #000000">;&nbsp;i&nbsp;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)<br><img id=Codehighlighter1_437_480_Open_Image onclick="this.style.display='none'; Codehighlighter1_437_480_Open_Text.style.display='none'; Codehighlighter1_437_480_Closed_Image.style.display='inline'; Codehighlighter1_437_480_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_437_480_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_437_480_Closed_Text.style.display='none'; Codehighlighter1_437_480_Open_Image.style.display='inline'; Codehighlighter1_437_480_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_437_480_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_437_480_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b[i][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;b[i][i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(&nbsp;i&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">;&nbsp;i&nbsp;</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">50</span><span style="COLOR: #000000">;&nbsp;i&nbsp;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)<br><img id=Codehighlighter1_519_606_Open_Image onclick="this.style.display='none'; Codehighlighter1_519_606_Open_Text.style.display='none'; Codehighlighter1_519_606_Closed_Image.style.display='inline'; Codehighlighter1_519_606_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_519_606_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_519_606_Closed_Text.style.display='none'; Codehighlighter1_519_606_Open_Image.style.display='inline'; Codehighlighter1_519_606_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_519_606_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_519_606_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(&nbsp;j&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;&nbsp;j&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;i;&nbsp;j&nbsp;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)<br><img id=Codehighlighter1_564_600_Open_Image onclick="this.style.display='none'; Codehighlighter1_564_600_Open_Text.style.display='none'; Codehighlighter1_564_600_Closed_Image.style.display='inline'; Codehighlighter1_564_600_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_564_600_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_564_600_Closed_Text.style.display='none'; Codehighlighter1_564_600_Open_Image.style.display='inline'; Codehighlighter1_564_600_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_564_600_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_564_600_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;add&nbsp;(&nbsp;i,&nbsp;j&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;print&nbsp;(&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;j&nbsp;)<br><img id=Codehighlighter1_639_857_Open_Image onclick="this.style.display='none'; Codehighlighter1_639_857_Open_Text.style.display='none'; Codehighlighter1_639_857_Closed_Image.style.display='inline'; Codehighlighter1_639_857_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_639_857_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_639_857_Closed_Text.style.display='none'; Codehighlighter1_639_857_Open_Image.style.display='inline'; Codehighlighter1_639_857_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_639_857_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_639_857_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;k;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(&nbsp;k&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">49</span><span style="COLOR: #000000">;&nbsp;k&nbsp;</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;k&nbsp;</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">&nbsp;)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(&nbsp;b[i][j][k]&nbsp;)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(&nbsp;k&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&nbsp;)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf&nbsp;(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(&nbsp;;&nbsp;k&nbsp;</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;k&nbsp;</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">&nbsp;)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf&nbsp;(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;b[i][j][k]&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;printf&nbsp;(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;print&nbsp;(&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n&nbsp;)<br><img id=Codehighlighter1_881_1443_Open_Image onclick="this.style.display='none'; Codehighlighter1_881_1443_Open_Text.style.display='none'; Codehighlighter1_881_1443_Closed_Image.style.display='inline'; Codehighlighter1_881_1443_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_881_1443_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_881_1443_Closed_Text.style.display='none'; Codehighlighter1_881_1443_Open_Image.style.display='inline'; Codehighlighter1_881_1443_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_881_1443_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_881_1443_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;printf&nbsp;(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;n&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,&nbsp;j,&nbsp;k;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;ans[</span><span style="COLOR: #000000">50</span><span style="COLOR: #000000">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;memset&nbsp;(&nbsp;ans,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">&nbsp;(&nbsp;ans&nbsp;)&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(&nbsp;i&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;i&nbsp;</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">&nbsp;n;&nbsp;i&nbsp;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)<br><img id=Codehighlighter1_1017_1113_Open_Image onclick="this.style.display='none'; Codehighlighter1_1017_1113_Open_Text.style.display='none'; Codehighlighter1_1017_1113_Closed_Image.style.display='inline'; Codehighlighter1_1017_1113_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1017_1113_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1017_1113_Closed_Text.style.display='none'; Codehighlighter1_1017_1113_Open_Image.style.display='inline'; Codehighlighter1_1017_1113_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_1017_1113_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1017_1113_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(&nbsp;j&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;j&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">50</span><span style="COLOR: #000000">;&nbsp;j&nbsp;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)<br><img id=Codehighlighter1_1063_1107_Open_Image onclick="this.style.display='none'; Codehighlighter1_1063_1107_Open_Text.style.display='none'; Codehighlighter1_1063_1107_Closed_Image.style.display='inline'; Codehighlighter1_1063_1107_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1063_1107_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1063_1107_Closed_Text.style.display='none'; Codehighlighter1_1063_1107_Open_Image.style.display='inline'; Codehighlighter1_1063_1107_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_1063_1107_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1063_1107_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans[j]&nbsp;</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">&nbsp;b[n][i][j];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;t,&nbsp;c&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(&nbsp;k&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;k&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">50</span><span style="COLOR: #000000">;&nbsp;k&nbsp;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)<br><img id=Codehighlighter1_1169_1244_Open_Image onclick="this.style.display='none'; Codehighlighter1_1169_1244_Open_Text.style.display='none'; Codehighlighter1_1169_1244_Closed_Image.style.display='inline'; Codehighlighter1_1169_1244_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1169_1244_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1169_1244_Closed_Text.style.display='none'; Codehighlighter1_1169_1244_Open_Image.style.display='inline'; Codehighlighter1_1169_1244_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_1169_1244_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1169_1244_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;ans[k]&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;c;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;t&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans[k]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;t&nbsp;</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(&nbsp;k&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">49</span><span style="COLOR: #000000">;&nbsp;k&nbsp;</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;k&nbsp;</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">&nbsp;)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(&nbsp;ans[k]&nbsp;)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(&nbsp;k&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&nbsp;)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf&nbsp;(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(&nbsp;;&nbsp;k&nbsp;</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;k&nbsp;</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">&nbsp;)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf&nbsp;(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;ans[k]&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;printf&nbsp;(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main&nbsp;()<br><img id=Codehighlighter1_1458_1618_Open_Image onclick="this.style.display='none'; Codehighlighter1_1458_1618_Open_Text.style.display='none'; Codehighlighter1_1458_1618_Closed_Image.style.display='inline'; Codehighlighter1_1458_1618_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_1458_1618_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1458_1618_Closed_Text.style.display='none'; Codehighlighter1_1458_1618_Open_Image.style.display='inline'; Codehighlighter1_1458_1618_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_1458_1618_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1458_1618_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">freopen&nbsp;(&nbsp;"in.txt",&nbsp;"r",&nbsp;stdin&nbsp;);</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;dp&nbsp;();<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">print&nbsp;(&nbsp;5,&nbsp;2&nbsp;);</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">&nbsp;(&nbsp;scanf&nbsp;(&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">N&nbsp;)&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;N&nbsp;)<br><img id=Codehighlighter1_1575_1602_Open_Image onclick="this.style.display='none'; Codehighlighter1_1575_1602_Open_Text.style.display='none'; Codehighlighter1_1575_1602_Closed_Image.style.display='inline'; Codehighlighter1_1575_1602_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1575_1602_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1575_1602_Closed_Text.style.display='none'; Codehighlighter1_1575_1602_Open_Image.style.display='inline'; Codehighlighter1_1575_1602_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_1575_1602_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1575_1602_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;(&nbsp;N&nbsp;);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span></div>
Rhyme Schemes
<hr>
<table cellSpacing=3 cellPadding=3 width="75%" border=1>
    <colgroup style="COLOR: red; TEXT-ALIGN: center" span=7>
    <tbody>
        <tr>
            <th height=40>Status</th>
            <th>In/Out</th>
            <th>TIME Limit</th>
            <th>MEMORY Limit</th>
            <th>Submit Times</th>
            <th>Solved Users</th>
            <th>JUDGE TYPE</th>
        </tr>
        <tr>
            <td align=middle height=40><span id=probinfo_placeholder><img height=20 src="http://acm.jlu.edu.cn/joj/images/ok1.gif" width=20></span></td>
            <td>stdin/stdout</td>
            <td>3s</td>
            <td>8192K</td>
            <td>97</td>
            <td>55</td>
            <td><strong>Special Test</strong></td>
        </tr>
    </tbody>
</table>
<div class=prob_text>
<p>The rhyme scheme for a poem (or stanza of a longer poem) tells which lines of the poem rhyme with which other lines. For example, a limerick such as
<pre><em>
If computers that you build are quantum
Then spies of all factions will want 'em
Our codes will all fail
And they'll read our email
`Til we've crypto that's quantum and daunt 'em
Jennifer and Peter Short(http://www.research.att.com/~shor/notapoet.html)
</em></pre>
Has a rhyme scheme of aabba, indicating that the first, second and fifth lines rhyme and the third and fourth lines rhyme.
<p>For a poem or stanza of four lines, there are 15 possible rhyme schemes: aaaa, aaab, aaba, aabb, aabc, abaa, abab, abac, abba, abbb, abbc, abca, abcb, abcc, and abcd.
<p>Write a program to compute the number of rhyme schemes for a poem or stanza of N lines where N is an input value.
<h3>Input</h3>
Input will consist of a sequence of integers N, one per line, ending with a 0 (zero) to indicate the end of the data. N is the number of lines in a poem.
<h3>Output</h3>
For each input integer N, your program should output the value of N, followed by a space, followed by the number of rhyme schemes for a poem with N lines as a decimal integer with at least 12 correct significant digits (use double precision floating point for your computations).
<h3>Sample Input</h3>
<pre>1
2
3
4
20
30
10
0
</pre>
<h3>Sample Output</h3>
<pre>1 1
2 2
3 5
4 15
20 51724158235372
30 846749014511809120000000
10 115975
</pre>
</div>
<p class=prob_src></p>
<hr>
<p>&nbsp; <br>排列组合的题目，大致上从小到大顺推即可。设b[i][j]中i表示字符串长度，j表示字符串中用到的字母个数，不难推出b[i][j] = b[i-1][j-1] + b[i - 1][j] * j。<br>而我自己的思路一直是想根据最后的那一个字母来推，推不出来</p>
<img src ="http://www.cppblog.com/luyulaile/aggbug/82667.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luyulaile/" target="_blank">luis</a> 2009-05-12 11:42 <a href="http://www.cppblog.com/luyulaile/archive/2009/05/12/82667.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>