锘??xml version="1.0" encoding="utf-8" standalone="yes"?>97久久超碰成人精品网站,精品国产91久久久久久久a,国产精品免费看久久久http://www.shnenglu.com/luyulaile/category/10546.htmlI canzh-cnTue, 28 Jul 2009 20:43:47 GMTTue, 28 Jul 2009 20:43:47 GMT60joj 1077 Transportation 鍥炴函 鍓灊http://www.shnenglu.com/luyulaile/archive/2009/07/25/91178.htmlluisluisSat, 25 Jul 2009 14:27:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/07/25/91178.htmlhttp://www.shnenglu.com/luyulaile/comments/91178.htmlhttp://www.shnenglu.com/luyulaile/archive/2009/07/25/91178.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/91178.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/91178.html1錛屼笉鍓灊涔熻兘榪囥?br>

 2錛屽鏋滃壀鏋濓紝
鏍規嵁鍥炴函鐨勮繃紼嬶紝浼氬厛姹傚埌
dfs(n)鏈鍚庨偅涓粨鐐癸紝鍐嶆槸dfs(n-1)..dfs(1)銆?br>鍓灊搴斿綋鏄湪緇撴瀯浣撲腑N[i]澧炲姞涓涓彉閲?/span>vnow,
vnow
鍒濆間負0錛岃褰曚粠璇ョ粨鐐瑰紑濮嬫悳绱㈡墍鏈?/span>int dfs(i)鐨勮繑鍥炲鹼紝騫朵笉鏂洿鏂頒嬌鍏舵渶澶э紝
褰撴悳绱㈠埌
i鐨勬椂鍊欙紝濡傛灉N[i].vnow涓嶄負0錛屽垯闇瑕佹弧瓚?/span>N[i].vnow+褰撳墠temp錛堝墠闈㈢殑鍙緋誨垪鐨勬誨鹼級>vmax(鎵瑕佹眰鐨勬渶澶у肩殑褰撳墠鍊?/span>)錛岃嫢vnow涓?/span>0錛屽垯鍙互涓嶆弧瓚寵繖涓潯浠訛紝鍥犱負榪欐槸絎竴嬈°?/span>

鏍規嵁鍥炴函鐨勮繃紼嬶紝絎竴嬈℃眰寰楃殑緇撴灉鏄?/span>dfs(n),鎺ヤ笅鏉ユ槸dfs(n-1)錛屾帴涓嬫潵鏄?/span>dfs(n-2)-------鏈鍚?/span>dfs(0);

luis 2009-07-25 22:27 鍙戣〃璇勮
]]>
joj 1305 Prime Ring Problem 緇忓吀娣辨悳http://www.shnenglu.com/luyulaile/archive/2009/07/11/89819.htmlluisluisSat, 11 Jul 2009 15:24:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/07/11/89819.htmlhttp://www.shnenglu.com/luyulaile/comments/89819.htmlhttp://www.shnenglu.com/luyulaile/archive/2009/07/11/89819.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/89819.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/89819.htmlA ring is composed of n (even number) circles as shown in diagram. Put natural numbers into each circle separately, and the sum of numbers in two adjacent circles should be a prime.


Note: the number of first circle should always be 1.

Input

n (0 < n <= 16)

Output

The output format is shown as sample below. Each row represents a series of circle numbers in the ring beginning from 1 clockwisely and anticlockwisely. The order of numbers must satisfy the above requirements.


You are to write a program that completes above process.

Sample Input

6
8

Sample Output

Case 1:
1 4 3 2 5 6
1 6 5 2 3 4
Case 2:
1 2 3 8 5 6 7 4
1 2 5 8 3 4 7 6
1 4 7 6 5 8 3 2
1 6 7 4 3 8 5 2


寰堢粡鍏哥殑娣辨悳錛屽惎鍙?br>1錛岄澶勭悊闈炲父閲嶈錛?br>錛?錛夛紝鍏堟眰鍑烘墍鏈夌殑prime鏁版渶澶?16+16錛宐ool isprime[32],
錛?錛夌敱浜庡凡緇忕粰鍑鴻寖鍥達紝鎴戜滑鍙互鍏堟眰鍑?-19鐨勬瘡涓暟涓嬩竴涓彲鑳界殑鍙栧鹼紝渚嬪15錛屼笅涓涓彲浠ュ彇2,4,------涓ら噸for寰幆錛屽彲浠ラ伩鍏嶆悳绱㈡椂閲嶅鍒ゆ柇銆?br>2錛岀敤涓涓暟緇勮褰曚嬌杈撳嚭鐨勬湁搴忥紝op[n]涓巇fs(int begin,int n)涓璶瀵瑰簲
 if( bp[t] )
       {
        op[o] = t ;
        o ++ ;
        bp[t] = false ; 
        dfs( t , n );//
        o -- ;
        bp[t] = true ;
       } 

luis 2009-07-11 23:24 鍙戣〃璇勮
]]>
joj 2391 words 娣辨悳鍓灊http://www.shnenglu.com/luyulaile/archive/2009/07/05/89274.htmlluisluisSun, 05 Jul 2009 04:33:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/07/05/89274.htmlhttp://www.shnenglu.com/luyulaile/comments/89274.htmlhttp://www.shnenglu.com/luyulaile/archive/2009/07/05/89274.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/89274.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/89274.html Status In/Out TIME Limit MEMORY Limit Submit Times Solved Users JUDGE TYPE stdin/stdout 3s 8192K 439 74 Standard

Io and Ao are playing a word game. They say a word in the dictionary by turns. The word in the dictionary only contains lowercase letters. And the end character of the former said word should be the same as the start character of the current said word. They can start the game from any word in the dictionary. Any word shouldn't be said twice. Now, we define the complexity of the game that is the sum length of all words said in the game. Give you a dictionary, can you tell me the max complexity of this word game?

Input

The first line contains a single positive integer n(0 < n <=12). Next n lines are n words in the dictionary. The length of each word will not exceed 100.

Output

A single integer represents the complexity of the game.

Sample Input

3
joj
jlu
acm
6
cctv
redcode
lindong
we
love
programming
3
daoyuanlee
come
on

Sample Output

6
11
10

Problem Source: provided by loon

#include<iostream>
#include<cstdlib>
using namespace std;
struct S
{
 string a;
 char begin;
 char end;
 int length;
 }s[13];
 int visited[13];
int temp; 
void search(int a,int num,int pre)
 {
  
  for(int i=0;i<num;i++ )
  {
   if(s[i].begin==s[pre].end&&visited[i]==0)
   {
    visited[i]=1;
    search(a+s[i].length,num,i);
    if(a+s[i].length>temp)temp=a+s[i].length;
    visited[i]=0;
   }
  }
 }
  int main()
  {
  freopen("s.txt","r",stdin);
  freopen("key.txt","w",stdout);
   int num;
   while(cin>>num)
   {
    int i;
  temp=0;
  for( i=0;i<num;i++)
  {
   cin>>s[i].a;
   s[i].length=(s[i].a).size();
   s[i].begin=(s[i].a)[0];
   s[i].end=(s[i].a)[s[i].length-1];
   if(s[i].length>temp)
   temp=s[i].length;
     }
  for(i=0;i<num;i++) 
     {
   memset(visited,0,sizeof(visited));
   visited[i]=1;
   search(s[i].length,num,i);
  }
  cout<<temp<<endl;
 }

  //system("PAUSE");
  return   0;
  }

浠ヤ笂浠g爜瓚呮椂銆傚畬鍏ㄥ彲浠ュ壀鏋濄?br>涓句釜渚嬪瓙
abc
cbd
dbm
dbacmdp
鎴戠殑紼嬪簭涓鐩存悳鍟婃悳錛屾瘡嬈℃悳瀹岄兘閲嶆柊寮濮嬨傛瘮濡傚湪浠寮澶村悗錛屾悳鍒癱錛屼笅嬈″啀鎼滅儲鏃剁洿鎺ュ埄鐢╟鐨勭粨鏋滐紝榪欐槸娣辨悳鐨勭壒鐐瑰喅瀹氱殑錛侊紒錛?br>*************************
榪欑綾諱技鐨勬湁搴忔悳绱㈤兘鍙互鐢?nbsp;    *  澶囧繕褰曟柟娉?
**************************
#include<iostream>
#include<cstdlib>
using namespace std;
int num;
struct S
{
 string a;
 char begin;
 char end;
 int length;
 }s[13];
 int visited[13];
int temp;
int sum[13]; 
int search(int pre)//·µ»Ø´ÓpreµãÒÔºóµÄ×ܵÄÖµ
 {
  int j=s[pre].length,k=0;
  for(int i=0;i<num;i++ )
  {
   if(s[i].begin==s[pre].end&&visited[i]==0&&i!=pre)//蹇呴』瑕佹湁I錛?pre
   {
    visited[i]=1;
    k=search(i)+s[pre].length;
    if(k>j)j=k;
   }
   else
   {
    if(s[i].begin==s[pre].end&&i!=pre)//蹇呴』瑕佹湁i!=pre
    return sum[i]+s[pre].length;//鐩稿綋浜庡蹇樺綍錛岃屼笖鏃犻渶visited[i]=0;
   }
  }
  sum[pre]=j;
  return j;
 }
  int main()
  {
 freopen("s.txt","r",stdin);
  freopen("key.txt","w",stdout);
   while(cin>>num)
   {
    int i,j;
  temp=0;
  j=0;
  for( i=0;i<num;i++)
  {
   cin>>s[i].a;
   s[i].length=(s[i].a).size();
   s[i].begin=(s[i].a)[0];
   s[i].end=(s[i].a)[s[i].length-1];
   if(s[i].length>temp)
   temp=s[i].length;
     }
  for(i=0;i<num;i++) 
     {
   memset(visited,0,sizeof(visited));
            memset(sum,0,sizeof(sum));
   visited[i]=1;
   j=search(i);
   if(j>temp)
   temp=j;
  }
  cout<<temp<<endl;
 }

  //system("PAUSE");
  return   0;
  }

鍥犱負I錛?pre鍙堥敊浜嗗嚑涓嬨?br>浠ュ悗debug灝介噺鑷繁鐢ㄧ溂鐫涚湅錛屾洿鐪佹椂闂達紒錛侊紒錛侊紒錛侊紒錛侊紒



luis 2009-07-05 12:33 鍙戣〃璇勮
]]>
joj 1867 squares 娣辨悳鐙傚壀鏋濓紝鐙傝秴鏃?/title><link>http://www.shnenglu.com/luyulaile/archive/2009/07/03/89196.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Fri, 03 Jul 2009 15:29:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2009/07/03/89196.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/89196.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2009/07/03/89196.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/89196.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/89196.html</trackback:ping><description><![CDATA[<p>閿欒浠g爜錛岃繃涓嶄簡鐨勬暟鎹?4錛?5 10 17 16 12 1 10 20 17 19 4 5 9 5  鍙兘瑙o細(20 15 5 ),(19 17 4 ),( 17 12 10 1 ), ( 16 10 9 5 )<br>涓嬮潰鐨勪唬鐮?#8220;no”錛屽洜涓?20 19 1),(17鎺ヤ笅鏉ュ噾涓嶅嚭鏉?nbsp;)<br>#include<iostream><br>#include<cstdlib><br>#include<algorithm><br>using namespace std;<br> int length[21];<br> int mark[21];<br> bool cmp(int x,int y)<br>{<br>    return x>y; <br>}</p> <p><br>  int  dfs(int sum,int flag,int n,int time)//´Ótime¿ªÊ¼ËÑË÷ <br>  {<br>  if(sum==0)return 1;<br>    if(time<n) <br>  {<br>   for(int k=time;k<n;k++)<br>   {<br>    if(mark[k]<0&&sum-length[k]>=0)<br>    {<br>     mark[k]=flag;<br>     if(dfs(sum-length[k],flag,n,k+1))<br>     return 1;<br>     else<br>     mark[k]=-1;<br>       } <br>   }<br>  }<br>     <br> return 0;<br>  }<br>  int main()<br>  {<br>  freopen("s.txt","r",stdin);<br>  freopen("key.txt","w",stdout);<br>  int num,n;<br> <br>  cin>>num;<br>  while(num--)<br>  {<br>  int sum=0;<br>  cin>>n;<br>  for(int k=0;k<n;k++)<br>  {<br>   cin>>length[k];<br>   mark[k]=-1;<br>   sum+=length[k];<br>  }<br>  sort(length,length+n,cmp);<br>  if(sum%4!=0||length[0]>sum/4)<br>  cout<<"no"<<endl;<br>  else<br>  {<br>   sum/=4;<br>   if(dfs(sum,1,n,0))<br>    {<br>   if(dfs(sum,2,n,0))<br>          {<br>     if(dfs(sum,3,n,0))<br>     cout<<"yes"<<endl;<br>     else<br>     cout<<"no"<<endl;<br>        } <br>        else<br>        cout<<"no"<<endl;<br>          }<br>         else<br>         cout<<"no"<<endl;<br>  }<br>    }<br>  //system("PAUSE");<br>  return   0;<br>  }<br>姝g‘鐨勮В娉曞簲褰撴槸錛屽湪涓璧鋒悳绱€?br>涓嬮潰鏄竴孌佃秴鏃剁殑浠g爜<br>#include<iostream><br>#include<cstdlib><br>#include<algorithm><br>using namespace std;<br> int length[21];<br> int mark[21];<br> int flag=0;<br> int target;<br> bool cmp(int x,int y)<br>{<br>    return x>y; <br>}</p> <p>  int func(int i)<br>  {<br>  while(mark[i]>0)<br>  i++;<br>  return i;<br> }<br>  void  dfs(int sum,int n,int time,int level)//浠庡簭鍙蜂負time鐨勫紑濮嬫悳绱?<br>  {<br>  if(flag)return ;<br>  if(sum==0&&level==3)<br>  {<br>  flag=1;<br>  return;<br>     }<br>     if(sum==0)<br>     {<br>   level++;<br>   dfs(target,n,func(0),level);<br>  }<br>    else if(time<n) <br>  {<br>   for(int k=time;k<n;k++)<br>   {<br>    if(k>1)<br>               {<br>                <br>                if(length[k]==length[k-1]&&!mark[k-1])<br>                    continue;//鏄劇劧 <br>               }<br>                if(sum<length[n-1])  continue;//鏄劇劧 <br>    if(mark[k]<0&&sum-length[k]>=0)<br>    {<br>     mark[k]=1;<br>     dfs(sum-length[k],n,func(k+1),level);<br>     mark[k]=-1;<br>       } <br>   }<br>  }<br>  }<br>  int main()<br>  {<br>  freopen("s.txt","r",stdin);<br>  freopen("key.txt","w",stdout);<br>  int num,n;<br> <br>  cin>>num;<br>  while(num--)<br>  {<br>  int sum=0;<br>  cin>>n;<br>  for(int k=0;k<n;k++)<br>  {<br>   cin>>length[k];<br>   mark[k]=-1;<br>   sum+=length[k];<br>  }<br>  sort(length,length+n,cmp);<br>  if(sum%4!=0||length[0]>sum/4)<br>  cout<<"no"<<endl;<br>  else<br>  {<br>   sum/=4;<br>   target=sum;<br>   dfs(sum,n,0,0);<br>       if(flag==0)<br>       cout<<"no"<<endl;<br>       else<br>       cout<<"yes"<<endl;<br>  }    <br>    }<br>  //system("PAUSE");<br>  return   0;<br>  }<br></p> <p>涓婇潰瓚呮椂灝辮秴鏃跺師鍥犳槸鍑忔灊涓嶅交搴曘俵evel鏍囪涔熶笉澶ソ<br>鍐沖畾鍙﹀鐐夌伓,鍏堢湅鐪嬪埆浜虹殑浠g爜<br>#include<iostream><br>#include<algorithm><br>using namespace std;<br>int s[21];<br>int v[21];<br>int len;<br>int m;<br>int dfs(int cur,int num,int beg,int fin)<br>{     <br> int solve(int );<br> if(num==1)<br>  return 1;<br> if(cur==len)<br> {<br>  return solve(num-1);<br> }<br>   for(int i=beg;i>=fin;i--)<br>   {<br>    if(!v[i]&&cur+s[i]<=len)<br>    {   <br>     v[i]=1;<br>     if(dfs(cur+s[i],num,i-1,fin))<br>      return 1;<br>     v[i]=0;<br>    }<br>   }<br>   return 0;<br>}</p> <p>int solve(int edge_num)<br>{    <br>     int i;<br>  for(i=m;i>=1;i--)<br>   if(!v[i])<br>   {  <br>    v[i]=1;<br>    if(dfs( s[i],edge_num,i-1,1))<br>     return 1;<br>    v[i]=0;<br>   }<br> return 0;<br>}</p> <p>int main()<br>{<br> int n;<br> cin>>n;<br> while(n--)<br> {<br>  <br>  cin>>m;<br>  int i;<br>  int sum=0;<br>  for(i=1;i<=m;i++)<br>  {<br>   cin>>s[i];<br>   sum+=s[i];<br>   v[i]=0;<br>  }<br>  <br>  len=sum/4;<br>  if(4*len!=sum)<br>  {<br>   cout<<"no"<<endl;<br>   continue;<br>  }<br>  sort(s+1,s+m+1);<br>  if(s[m]>len)<br>  {<br>   cout<<"no"<<endl;<br>   continue;<br>  }<br>  if(solve(4))<br>   cout<<"yes"<<endl;<br>  else<br>   cout<<"no"<<endl;<br> }<br> return 0;<br>}//鍓灊榪樺彲浠ュ仛寰楁洿濂斤紒錛侊紒<br>浜哄鐨剆olve鍐欏緱濂斤紒錛侊紝緇撳悎dfs.</p> <img src ="http://www.shnenglu.com/luyulaile/aggbug/89196.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2009-07-03 23:29 <a href="http://www.shnenglu.com/luyulaile/archive/2009/07/03/89196.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>joj 2250 my friends娣卞害浼樺厛鎼滅儲璁茶Вhttp://www.shnenglu.com/luyulaile/archive/2009/06/29/88782.htmlluisluisMon, 29 Jun 2009 08:13:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/06/29/88782.htmlhttp://www.shnenglu.com/luyulaile/comments/88782.htmlhttp://www.shnenglu.com/luyulaile/archive/2009/06/29/88782.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/88782.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/88782.htmlInput The input consists of a number of cases. The first line on each case contains a positive number n (1 < n <= 100) that specifies the number of points in the graph. A value of n = 0 indicates the end of the input. After this, a second number s is provided, indicating the starting point in my journey (1 <= s <= n). Then, you are given a list of pairs of places p and q, one pair per line. The pair "p q" indicates that I can visit q after p. A pair of zeros ("0 0") indicates the end of the case. As mentioned before, you can assume that the graphs provided will not be cyclic.

Output

For each test case you have to find the length of the longest path that begins at the starting place. You also have to print the number of the final place of such longest path. If there are several paths of maximum length, print the final place with smallest number.

Print a new line after each test case.

Sample Input

2
1
1 2
0 0
5
3
1 2
3 5
3 1
2 4
4 5
0 0
5
5
5 1
5 2
5 3
5 4
4 1
4 2
0 0
0

Sample Output

Case 1: The longest path from 1 has length 1, finishing at 2.
Case 2: The longest path from 3 has length 4, finishing at 5.
Case 3: The longest path from 5 has length 2, finishing at 1.
鎻愪氦浜?0嬈★紝AC 3嬈★紝瓚呮椂4嬈★紝wa 3嬈°?/pre>
寰堟棤璇?/pre>
搴旇鏄姩鎬佽鍒掓渶濂斤紝浣嗘槸鎴戜笉鏄緢鐔燂紝鐢ㄤ簡鎼滅儲銆備互涓嬫槸瓚呮椂鐨勪唬鐮?/pre>
#include<iostream>
#include<cstdlib>
using namespace std;
int path[101][101];
int mark[101];
int len[101];//
int end[101];
int dfs(int start,int num)//榪斿洖浠庡綋鍓嶇偣鍑哄彂鐨勬渶澶ч暱搴?
{
if(mark[start]==1)return len[start];
mark[start]=1;
end[start]=start;
for(int i=1;i<=num;i++)
{
if(path[start][i])
{
if(len[start]<dfs(i,num)+1)
{
len[start]=len[i]+1;
end[start]=end[i];
}
else
if(len[start]==len[i]+1&&end[start]>end[i])
end[start]=end[i];
}
}
mark[start]=0;//榪欏彞鍧氬喅涓嶉渶瑕?
return len[start];
}
int main()
{
// freopen("s.txt","r",stdin);
//freopen("key.txt","w",stdout);
int j,k,turn=0;
int start,num;
while(cin>>num)
{
turn++;
if(num==0)break;
memset(path,0,sizeof(path));
memset(mark,0,sizeof(mark));
memset(len,0,sizeof(len));
memset(end,0,sizeof(end));
cin>>start;
while(cin>>j>>k)
{
if(j==0)break;
path[j][k]=1;
}
cout<<"Case "<<turn<<": The longest path from "<<start<<" has length "<<dfs(start,num)<<", finishing at "<<end[start]<<"."<<endl<<endl;
}
//system("PAUSE");
return   0;
}
浠ヤ笅鏄痑c鐨勪唬鐮?/pre>
#include<iostream>
#include<cstdlib>
using namespace std;
int path[102][102];
int mark[102], len[102],end[102];
int dfs(int start,int num)//榪斿洖浠庡綋鍓嶇偣鍑哄彂鐨勬渶澶ч暱搴?
{
if(mark[start]==1)return len[start];
mark[start]=1;
end[start]=start;
len[start]=0;
int i,t;
for( i=1;i<=num;i++)
{
if(path[start][i])
{
t=dfs(i,num)+1;
if(t>len[start])
{
len[start]=t;
end[start]=end[i];
}
else
if(len[start]==t)
{
if(end[start]>end[i])
end[start]=end[i];
}
}
}
return len[start];
}
int main()
{
//freopen("s.txt","r",stdin);
//freopen("key.txt","w",stdout);
int j,k,turn=0;
int start,num;
while(cin>>num,num)
{
turn++;
memset(path,0,sizeof(path));
memset(mark,0,sizeof(mark));
memset(len,0,sizeof(len));
memset(end,0,sizeof(end));
cin>>start;
while(cin>>j>>k,j||k)
{
path[j][k]=1;
}
dfs(start,num);
cout<<"Case "<<turn<<": The longest path from "<<start<<" has length "<<len[start]<<", finishing at "<<end[start]<<"."<<endl<<endl;
}
//system("PAUSE");
return   0;
}
涓嶅Θ鎵ц涓涓?/pre>
5
3
1 2
3 5
3 1
2 4
4 5
0 0
鍏堟槸len[3]=0;end[3]=3;flag[3]=1;
鍐嶆墽琛宼=dfs(1)+1,
杞叆dfs錛?錛夛紱len[1]=0;end[1]=1;flag[1]=1;
鍐嶆墽琛?span style="COLOR: #0000ff">t=dfs(2)+1;
杞叆dfs(2),len[2]=0;end[2]=2;flag[2]=1;
鍐嶆墽琛宼=dfs(4)+1
杞叆dfs(4),len[4]=0;end[4]=4;flag[4]=1;
鍐嶈漿鍏?span style="COLOR: red">t=dfs錛?)+1;
杞叆dfs(5),len[5]=0;end[5]=5;flag[5]=1;return(len[5]=0);
鍒檛=1;t>len[4];len[4]=1;end[4]=end[5]=5;鍐嶇湅4娌′簡鍏朵粬鐩擱偦鍏冪礌銆俤fs(4)=return(len[4])=1;
t=dfs(4)+1=2;len[2]=t=2;end[2]=end[4]=5;鍐嶇湅2娌′簡鍏朵粬鐩擱偦鍏冪礌錛宒fs(2)=return(len(2)=2;
鍐嶇湅t=dfs(2)+1=3;len[1]=t=3;end[1]=en[2]=5;鍐嶇湅1鏈夋病鏈夊叾浠栫浉閭誨厓绱狅紝dfs(1)=return(len(1)=3
鍐嶆墽琛宼=dfs(1)+1,len[3]=4;end[3]=end[1]=5;鍐嶇湅3鏈夋病鏈夊叾浠栫浉閭誨厓绱狅紝鏈塪fs(5),宸茬粡閬嶅巻鍒頒簡錛屾墍浠fs錛?錛塺eturn len銆?銆戙?br>娌℃湁褰卞搷銆?br>鍋囪鏀逛負
5 3 5 2 3 5 3 1 2 4 4 1 0 0 鎵ц鏃朵細璧?->1>榪欐椂鐨?緇撶偣len[1]宸茬粡姹傜殑 3>5>2>4>1len[1]宸茬煡浜?/span>


luis 2009-06-29 16:13 鍙戣〃璇勮
]]>joj 2390娣卞害鎼滅儲錛屽崟鎸戣礬寰勪笉鍏佽閲嶅http://www.shnenglu.com/luyulaile/archive/2009/06/28/88705.htmlluisluisSun, 28 Jun 2009 10:11:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/06/28/88705.htmlhttp://www.shnenglu.com/luyulaile/comments/88705.htmlhttp://www.shnenglu.com/luyulaile/archive/2009/06/28/88705.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/88705.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/88705.html#include <iostream>
using namespace std;

int path[6][6];
int row,col,v,h;

bool OK(int i,int j)
{
if(i>=0 && i<row && j>=0 && j<col)
   
return true;
return false;
}

void DFS(int i,int j,int & counts)
{
if(path[i][j]==1)
{
   
if(i==&& j==h)
    counts
++;
   
return ;
}
path[i][j]
=1;
if(OK(i-2,j-1))
   DFS(i
-2,j-1,counts);
if(OK(i-2,j+1))
   DFS(i
-2,j+1,counts);
if(OK(i-1,j-2))
   DFS(i
-1,j-2,counts);
if(OK(i+1,j-2))
   DFS(i
+1,j-2,counts);
if(OK(i-1,j+2))
   DFS(i
-1,j+2,counts);
if(OK(i+1,j+2))
   DFS(i
+1,j+2,counts);
if(OK(i+2,j-1))
   DFS(i
+2,j-1,counts);
if(OK(i+2,j+1))
   DFS(i
+2,j+1,counts);
path[i][j]
=0;
}
int main()
{
    freopen(
"s.txt","r",stdin);
  freopen(
"key.txt","w",stdout);
while(cin>>row>>col>>v>>h)
{
   memset(path,
0,sizeof(path));
   
int counts=0;
   DFS(v,h,counts);
   cout
<<counts<<endl;
}
return 0;
}

On a chess board sizes of m*n(1<=m<=5,1<=n<=5),given a start position,work out the amount of all the different paths through which the horse could return to the start position.(The position that the horse passed in one path must be different.The horse jumps in a way like "鏃?)

Input

The input consists of several test cases.The size of the chess board m,n(row,column),and the start position v,h(vertical , horizontal) ,separated by a space.The left-up point is (0,0)

Output

the amount of the paths in a single line

Sample Input

5 4 3 1

Sample output

4596
瑙f瀽錛?br>椹蛋鏃ワ紝鍏釜鏂瑰悜錛?br>涓嶅厑璁告煇鏉¤礬寰勪笂閲嶅銆?br>if(path[i][j]==1)
{
   if(i==v && j==h)
    counts++;
//閲嶅鐨勫鏋滄槸鍑哄彂鐐癸紝榪斿洖鍊?br>   return ;//鏃犺鎬庢牱錛屽彧瑕侀噸澶嶅氨榪斿洖
}


luis 2009-06-28 18:11 鍙戣〃璇勮
]]>
joj 2534 浼樺厛闃熷垪妯℃澘 騫挎悳http://www.shnenglu.com/luyulaile/archive/2009/05/14/82991.htmlluisluisThu, 14 May 2009 13:49:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/05/14/82991.htmlhttp://www.shnenglu.com/luyulaile/comments/82991.htmlhttp://www.shnenglu.com/luyulaile/archive/2009/05/14/82991.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/82991.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/82991.html#include<iostream>
#include
<queue>
#include
<vector>
#include
<stack>
using namespace std;
char a[15][30];
bool b[15][30];
int sx,sy,tx,ty;
int ix[4]={0,0,1,-1};
int iy[4]={1,-1,0,0};

 
struct Node
{
    
int x,y;
    
int days;
};
class cmp
{
    
public:
        
bool operator ()(const Node & a, const Node & b)
        {
            
return a.days>b.days;   //СµÄÏÈpop()³öÀ´£¬Í¬Àí¿ÉÒÔ¶¨ÒåÓÅÏÈ´óµÄ¶ÓÁР
        }    
};    

priority_queue
<Node,vector<Node>,cmp> qu;  
int bfs()
{
     
int cx,cy;
     
int tex,tey;
     
int steps;
     Node node;
     node.x
=sx,node.y=sy,node.days=0;
     
while(!qu.empty()) qu.pop();
     qu.push(node);
     
while(!qu.empty())
     {
         node
=qu.top();
         qu.pop();
         steps
=node.days;
         cx
=node.x;
         cy
=node.y;
         
for(int i=0;i<4;i++)
         {
             tex
=cx+ix[i];
             tey
=cy+iy[i];
             
if(tex>=0 && tex<15 && tey>=0 && tey<30 && b[tex][tey]==false&& a[tex][tey]!='#')
             {
                 node.x
=tex;
                 node.y
=tey;
                 
if(a[tex][tey]=='.')
                    node.days
=steps+1;
                 
else if(a[tex][tey]=='M')
                    node.days
=steps+2;
                 
else if(a[tex][tey]='T')
                 
return  steps+1;
                 b[tex][tey]
=true;
                 qu.push(node);
             }                 
         }    
     }    
}   
 
int main()
{
   
// freopen("s.txt","r",stdin);
    
//freopen("key.txt","w",stdout); 
    int ca,i,j;    
    scanf(
"%d",&ca);
    getchar();
    
while(ca--)
    {
        memset(b,
0,sizeof(b));
        
for(i=0;i<15;i++)
        {
            
for(j=0;j<30;j++)
            {
                scanf(
"%c",&a[i][j]);
                
if(a[i][j]=='S')
                   sx
=i,sy=j;
                
else if(a[i][j]=='T')
                   tx
=i,ty=j;
            }    
            getchar();
        }
        b[sx][sy]
=1;
        printf(
"%d\n",bfs());
    }    
    
return 0;
}
鍚彂錛氬畾涔夊彉閲忔椂鏈濂借兘璧嬩簣瀹為檯鐨勬剰涔夛紒錛?br>           濂界殑涔犳儻錛岃嫢鏄叧閿瓧鍙崲涓哄ぇ鍐欏瓧姣嶅彉閲?br>           璋冭瘯涓姝ヤ竴姝ョ殑錛佽偗瀹氭槸鏈夐棶棰樼殑涓姝ユ鏉?

luis 2009-05-14 21:49 鍙戣〃璇勮
]]>
joj 1349 Oil Deposits錛?a waste of time in debug 娣辨悳 璋冭瘯浜嗕竴灝忔椂鍙洜涓烘妸=鍐欐垚浜?=錛?/title><link>http://www.shnenglu.com/luyulaile/archive/2009/05/14/82988.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Thu, 14 May 2009 13:21:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2009/05/14/82988.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/82988.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2009/05/14/82988.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/82988.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/82988.html</trackback:ping><description><![CDATA[<p> </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"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">cstdlib</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> std;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> MATRIX[</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> fx[</span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">0</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">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">1</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">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">},fy[</span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</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">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</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">,</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> row,col;<br>  </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> ISALL()<br>  {<br>      </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i,j,mark</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>      </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">row;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>       {<br>       </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">col;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>       {<br>           </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(MATRIX[i][j]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br>             mark</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;              <br>       }<br>       }<br>       </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> mark;<br>  }<br>  </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">  check(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> j,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> k)<br>  {<br>      </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> f</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>      </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">((i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">>=</span><span style="COLOR: #000000">row)</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">>=</span><span style="COLOR: #000000">col))<br>       f</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>      </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> f;<br>  }<br>  </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> dfs(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> j)<br>  {<br>       </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> newx,newy;<br>       </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>       {<br>         newx</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">fx[k];<br>         newy</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">fy[k];      <br>         </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(check(newx,newy,k)</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000">MATRIX[newx][newy]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br>         {<br>             MATRIX[newx][newy]</span><span style="COLOR: #000000">=-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;                                            <br>             dfs(newx,newy);              <br>         }              <br>       }<br>  }<br>  </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main()<br>  {<br>  freopen(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">s.txt</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">r</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,stdin);<br>  freopen(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">key.txt</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">w</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,stdout);<br>  </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> flag,times;<br>  </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i,j;<br>  </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> m;<br>  cin</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">row</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">col;<br>  </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(row</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>  {<br>    memset(MATRIX,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(MATRIX));           <br>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">row;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">col;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>    {<br>      cin</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">m;<br>      </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(m</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">@</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)MATRIX[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">ÓÃ1±íʾ@ ,0±íʾ*,·ÃÎÊÖ®ºó¸ÄΪ-1               </span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">    } <br>    flag</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">times</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">row</span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000">flag</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">col</span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000">flag</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>    {<br>        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(MATRIX[i][j]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br>        {<br>          MATRIX[i][j]</span><span style="COLOR: #000000">=-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;                 <br>          dfs(i,j);<br>          times</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>         </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(ISALL()</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)flag</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;   <br>         }<br>                    <br>    }  <br>    cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">times</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">endl;        <br>    cin</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">row</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">col;           <br>  }<br><br>  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">system("PAUSE");</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">  </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">   </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>  }<br></span></div> <img src ="http://www.shnenglu.com/luyulaile/aggbug/82988.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2009-05-14 21:21 <a href="http://www.shnenglu.com/luyulaile/archive/2009/05/14/82988.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>joj 1197 &&poj 1564 Sum It Up,寰堝閥濡欏鐞嗘湁閲嶅鐨勬繁鎼滃壀鏋?/title><link>http://www.shnenglu.com/luyulaile/archive/2009/05/14/82965.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Thu, 14 May 2009 08:32:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2009/05/14/82965.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/82965.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2009/05/14/82965.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/82965.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/82965.html</trackback:ping><description><![CDATA[Sum It Up <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>424</td> <td>182</td> <td>Standard</td> </tr> </tbody> </table> <div id="pdbxrbh" class=prob_text> <p>Given a specifie d total <em>t</em> and a list of <em>n</em> integers, find all distinct sums using numbers from the list that add up to <em>t</em>. For example, if <em>t</em> = 4, <em>n</em> = 6, and the list is [4, 3, 2, 2, 1, 1], then there are four different sums that equal 4: 4, 3+1, 2+2, and 2+1+1. (A number can be used within a sum as many times as it appears in the list, and a single number counts as a sum.) Your job is to solve this problem in general. </p> <p> <h3>Input</h3> <p>The input file will contain one or more test cases, one per line. Each test case contains <em>t</em>, the total, followed by <em>n</em>, the number of integers in the list, followed by <em>n</em> integers <img height=30 src="http://acm.jlu.edu.cn/joj/images/problems/1197.gif" width=80 align=middle border=0>. If <em>n</em> = 0 it signals the end of the input; otherwise, <em>t</em> will be a positive integer less than 1000, <em>n</em> will be an integer between 1 and 12 (inclusive), and <img height=30 src="http://acm.jlu.edu.cn/joj/images/problems/1197.gif" width=80 align=middle border=0> will be positive integers less than 100. All numbers will be separated by exactly one space. The numbers in each list appear in nonincreasing order, and there may be repetitions. </p> <p> <h3>Output</h3> <p>For each test case, first output a line containing `<tt>Sums of </tt>', the total, and a colon. Then output each sum, one per line; if there are no sums, output the line `<tt>NONE</tt>'. The numbers within each sum must appear in nonincreasing order. A number may be repeated in the sum as many times as it was repeated in the original list. The sums themselves must be sorted in decreasing order based on the numbers appearing in the sum. In other words, the sums must be sorted by their first number; sums with the same first number must be sorted by their second number; sums with the same first two numbers must be sorted by their third number; and so on. Within each test case, all sums must be distinct; the same sum cannot appear twice. </p> <p> <h3>Sample Input</h3> <pre>4 6 4 3 2 2 1 1 5 3 2 1 1 400 12 50 50 50 50 50 50 25 25 25 25 25 25 0 0 </pre> <p> <h3>Sample Output</h3> <pre>Sums of 4: 4 3+1 2+2 2+1+1 Sums of 5: NONE Sums of 400: 50+50+50+50+50+50+25+25+25+25 50+50+50+50+50+25+25+25+25+25+25 <br></pre> <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"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">cstdlib</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">memory</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> std;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> mount;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> l;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> a[</span><span style="COLOR: #000000">12</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> mark;<br>  </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> output()<br>  {<br>    mark</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;   <br>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> temp[</span><span style="COLOR: #000000">12</span><span style="COLOR: #000000">];   <br>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> flag</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">mount;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>    {  <br>     </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a[i][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])<br>    {<br>      </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(flag</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>      flag</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>      </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br>      cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br>     cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">a[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];<br>     }                          <br>    }          <br>     cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">endl;            <br>  }<br>  </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> dfs(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> sum,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> nowv,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> pre)<br>  {<br>       </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> value;<br>       </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(nowv</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">sum)<br>       {<br>          output();         <br>       }<br>       </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br>       {<br>           </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">pre</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">mount;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>           {<br>             value</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[j][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];      <br>             </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(nowv</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">value</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">sum</span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000">value</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">l)<br>             { <br>             a[j][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;                                                       <br>             dfs(sum,nowv</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">value,j);<br>             a[j][</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>             }   <br>           }<br>       }<br>       </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(pre</span><span style="COLOR: #000000">!=-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br>       l</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[pre][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];<br>  }<br>  </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main()<br>  {<br>  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">freopen("s.txt","r",stdin);<br>  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">freopen("key.txt","w",stdout);</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">  </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> sum,i,j;<br>  cin</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">sum</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">mount;<br>  </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(sum</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>  {           <br>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">mount;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>    {<br>       cin</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">a[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];<br>       a[i][</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>    }<br>    <br>    mark</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>    l</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>    cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Sums of </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">sum</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">:</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">endl;<br>    dfs(sum,</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>    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(mark</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>    cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">NONE</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">endl;         <br>    cin</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">sum</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">mount;         <br>  }<br>  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">system("PAUSE");</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">  </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>  }<br></span></div> <p> </p> 闅劇偣錛?錛屾湁搴忛掑噺錛岃繖涓ソ澶勭悊錛屽彧闇鍦ㄥ悜鍓嶆帹鏃禿fs(i)for(int j=i+1...)鍗沖彲<br>            2錛屽幓鎺夋棤鏁堢殑閲嶅鎼滅儲錛岃繖涓儲涓鐐?姣斿鍜屼負11鏃訛紝搴忓垪涓?,6,6,2,2,2,1錛?+2+2+1鏄劇劧鏄彲浠ョ殑錛屼絾鏄?+6涓嶅彲浠ャ?+6+6鏇翠笉鍙互<br>鎴戜滑鍙互榪欐牱鎯籌紝濡傛灉欏虹潃寰鍓嶆帹鏄紝濡傛灉涓嶈秴榪囪寖鍥達紝姣斿6+2+鍙栧悗涓涓暟鏃訛紝2鍙互鍙栵紝浣嗘槸6+6錛岃秴榪?1錛岃鍥炴函鐨勬椂鍊欙紝璁板綍涓嬫鏃剁殑6錛岀敤涓嬮潰鐨勪唬鐮?br><br>if(pre!=-1)<br>       l=a[pre][0];<br><br>鍦ㄦ瘮杈僫f(nowv+value<=sum&&value!=l)姝ゆ椂涓嶇鍚堬紝涓嬩竴涓?鍙栦笉鍒頒簡錛侀伩鍏嶄簡閲嶅銆?/div> <img src ="http://www.shnenglu.com/luyulaile/aggbug/82965.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2009-05-14 16:32 <a href="http://www.shnenglu.com/luyulaile/archive/2009/05/14/82965.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>poj 3126 騫挎悳 Prime Pathhttp://www.shnenglu.com/luyulaile/archive/2009/05/13/82888.htmlluisluisWed, 13 May 2009 15:32:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/05/13/82888.htmlhttp://www.shnenglu.com/luyulaile/comments/82888.htmlhttp://www.shnenglu.com/luyulaile/archive/2009/05/13/82888.html#Feedback2http://www.shnenglu.com/luyulaile/comments/commentRss/82888.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/82888.html#include<iostream>
#include
<queue>
#include
<math.h>
using namespace std;
const int MAX=10000;
int visited[10000];
int result[10000];
bool isprimer(int npp)
 {
     
for (int q = 2; q <= sqrt(double(npp)); ++q)
     {
         
if (npp % q == 0)
         {
             
return 0;
         }
     }
     
return 1;
 
 }

int BFS(int start,int end) 
{
    queue
<int> q;
    
if (start == end)
        
return 0;
    q.push(start);
    visited[start]
=1;
    result[start]
=0;
    
while(!q.empty()) 
    {
        
int temp=q.front();
        q.pop();
        
int next,j,k;
        
int num[3];
        
        
for (int i =0;i<4;++i)
            {    
                 num[
0]=temp%10;
                 num[
1]=(temp%100)/10;
                 num[
2]=(temp%1000)/100;
                 num[
3]=temp/1000;   
                 
for(j=0;j<=9;j++)      
               {                       
                 num[i]
=j;
                 next
=num[0]+num[1]*10+num[2]*100+num[3]*1000;
                 
                 
if((next>1000&&visited[next]!=1)&&isprimer(next))
                 {
                     q.push(next);
                     result[next]
=result[temp]+1;
                     visited[next]
=1;                                             
                 }
                 
if(next==end)
                 {
                   
return result[next];           
                 }
              }     
            } 
    }
    
return MAX;
}
int main() {
    
//freopen("s.txt","r",stdin);
    
//freopen("key.txt","w",stdout);
    int n,k,j,m;
    cin
>>j;
    
while(j--)
    {
    memset(visited,
0,sizeof(visited));
    memset(result,
0,sizeof(result));          
    cin
>>n>>k;
    m
=BFS(n,k);
    
if(m!=MAX)          
    cout
<<m<<endl;
    
else
    cout
<<"Impossible"<<endl;
    }
    
return 0;
}

Description

The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their offices.
鈥?It is a matter of security to change such things every now and then, to keep the enemy in the dark.
鈥?But look, I have chosen my number 1033 for good reasons. I am the Prime minister, you know!
鈥?I know, so therefore your new number 8179 is also a prime. You will just have to paste four new digits over the four old ones on your office door.
鈥?No, it’s not that simple. Suppose that I change the first digit to an 8, then the number will read 8033 which is not a prime!
鈥?I see, being the prime minister you cannot stand having a non-prime number on your door even for a few seconds.
鈥?Correct! So I must invent a scheme for going from 1033 to 8179 by a path of prime numbers where only one digit is changed from one prime to the next prime.

Now, the minister of finance, who had been eavesdropping, intervened.
鈥?No unnecessary expenditure, please! I happen to know that the price of a digit is one pound.
鈥?Hmm, in that case I need a computer program to minimize the cost. You don't know some very cheap software gurus, do you?
鈥?In fact, I do. You see, there is this programming contest going on... Help the prime minister to find the cheapest prime path between any two given four-digit primes! The first digit must be nonzero, of course. Here is a solution in the case above.
1033
1733
3733
3739
3779
8779
8179
The cost of this solution is 6 pounds. Note that the digit 1 which got pasted over in step 2 can not be reused in the last step – a new 1 must be purchased.

Input

One line with a positive number: the number of test cases (at most 100). Then for each test case, one line with two numbers separated by a blank. Both numbers are four-digit primes (without leading zeros).

Output

One line for each case, either with a number stating the minimal cost or containing the word Impossible.

Sample Input

3
1033 8179
1373 8017
1033 1033

Sample Output

6
7
0

浠g爜瀹屽叏鍙互浼樺寲錛屾瘮濡傚畾涔変竴涓粨鏋勪綋鍙互鐪佹帀result鏁扮粍錛?br>鎳掑緱鏀逛簡
鍙戠幇poj姣攋oj鏇存儕蹇冨姩欖勫晩錛佺粡甯竎ompling,緇撴灉鍗婂ぉ鎵嶅嚭鐜幫紒

luis 2009-05-13 23:32 鍙戣〃璇勮
]]>
joj 2510 Product綆鍗曠殑娣卞害浼樺厛鎼滅儲http://www.shnenglu.com/luyulaile/archive/2009/05/12/82735.htmlluisluisTue, 12 May 2009 14:18:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/05/12/82735.htmlhttp://www.shnenglu.com/luyulaile/comments/82735.htmlhttp://www.shnenglu.com/luyulaile/archive/2009/05/12/82735.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/82735.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/82735.html#include<iostream>
using namespace std;
int num[100];
int a,s;
int MAX;
void search(int i,int sum)
{
     
int j;
     
if(i==a)//鍒拌揪緇堢偣鐨勫鐞?/span>
     {
     
if(sum*(s-sum)>MAX)
        MAX
=sum*(s-sum);
     }
     
else
     
for(j=0;j<2;j++)//鍚勪釜鏀礬
     {
          
//鐞嗚涓婂簲褰撴坊鍔犳潯浠跺垽鏂?/span>
          search(i+1,sum+j*num[i-1]);
     }
}
int main()
{
   
int b,c,sum;
   
while(cin>>a)
   {       
         sum
=0;
         s
=0;
         MAX
=0;       
         
for(b=0;b<a;b++)
         {
             cin
>>num[b];
             s
+=num[b];            
         }
         search(
0, sum);//浠庤繖閲屽紑濮?/span>
         cout<<MAX<<endl;
                
   } 
}
榪樻湁涓鐐瑰惎鍙戯紝max涓嶈兘鐢紝鍙互鐢∕AX錛屾棤闇璁板綍

There are multiple test cases, the first line of each test case is a integer n. (2<=n<=20) The next line have n integers (every integer in the range [1,1000]). We can divide these n integers into two parts and get the sum of the integers in these two parts, define them as sumA and sumB. Please calc the max number of sumA*sumB and output it in a single line.

Sample Input

3
5 3 7
2
4 9

Sample Output

56
36

Hint

(5,3),(7)  sumA=8  sumB=7  sumA*sumB=56
(5),(3,7)  sumA=5  sumB=10 sumA*sumB=50
(3),(5,7)  sumA=3  sumB=12 sumA*sumB=36
(),(3,5,7) sumA=0  sumB=15 sumA*sumB=0
The max is 56.


luis 2009-05-12 22:18 鍙戣〃璇勮
]]>
亚洲国产天堂久久综合网站| 久久婷婷五月综合色高清| 老司机国内精品久久久久| 国产精品久久久99| 久久久久久亚洲精品无码| 久久人人爽人人人人片av| 精品久久久久久久无码 | 久久天天婷婷五月俺也去| 一本一道久久综合狠狠老| 99精品久久精品| 人妻无码久久精品| 久久免费美女视频| 亚洲伊人久久精品影院| 久久国产成人午夜aⅴ影院 | 久久中文字幕人妻熟av女| 777米奇久久最新地址| 亚洲国产成人久久综合区| 一本一道久久精品综合| 久久精品国产99国产精品导航 | 欧美无乱码久久久免费午夜一区二区三区中文字幕| 日日狠狠久久偷偷色综合96蜜桃| 国产精品久久久久影院色 | 97r久久精品国产99国产精| 久久综合鬼色88久久精品综合自在自线噜噜| 久久亚洲精品国产精品| 亚洲国产视频久久| 一级做a爰片久久毛片毛片| 看全色黄大色大片免费久久久| 久久综合九色综合久99| 国产亚洲精品美女久久久| 人妻无码αv中文字幕久久| 久久天天躁夜夜躁狠狠躁2022| 久久久久亚洲精品天堂久久久久久 | AV色综合久久天堂AV色综合在 | 四虎国产永久免费久久| 久久婷婷五月综合97色一本一本 | 香蕉aa三级久久毛片| 久久免费美女视频| 欧美一区二区精品久久| 久久精品国产一区| 国内精品久久久久久久coent|