標籤:des style http color os io strong for
題目連結:啊哈哈,點我點我
題意:有n個幼兒園的孩紙,然後從中找出m對孩子能夠讓他們看到雙方,這樣以便他們交流。。思路:首先可以考慮把n-1個人已經排成了m-2對,那麼只需要把這個最矮的隨便插在隊伍就可以湊成m對了。另外一種情況是先排成m-1對,然後把最矮的那一個放在對首或者隊尾,這樣就到了狀態轉移方程。if(j>=2)dp[i][j]=dp[i-1][j-2]*(i-2)if(j>=1)dp[i][j]=dp[i][j]+dp[i-1][j-1]*2;然後最開始把1個人2個人的所有狀態枚舉出來。。然後對題目中給的範圍進行預先處理得到所有解,然後直接詢問即可。問題就得到了完美的解決。題目:Queue
| Time Limit: 1000MS |
|
Memory Limit: 65536K |
| Total Submissions: 406 |
|
Accepted: 179 |
Description
Linda is a teacher in ACM kindergarten. She is in charge of n kids. Because the dinning hall is a little bit far away from the classroom, those n kids have to walk in line to the dinning hall every day. When they are walking in line, if and only if two kids can see each other, they will talk to each other. Two kids can see each other if and only if all kids between them are shorter then both of them, or there are no kids between them. Kids do not only look forward, they may look back and talk to kids behind them. Linda don’t want them to talk too much (for it’s not safe), but she also don’t want them to be too quiet(for it’s boring), so Linda decides that she must form a line in which there are exactly m pairs of kids who can see each other. Linda wants to know, in how many different ways can she form such a line. Can you help her?
Note: All kids are different in height.
Input
Input consists of multiple test cases. Each test case is one line containing two integers. The first integer is n, and the second one is m. (0 < n <= 80, 0 <= m <= 10000).
Input ends by a line containing two zeros.
Output
For each test case, output one line containing the reminder of the number of ways divided by 9937.
Sample Input
1 02 03 20 0
Sample Output
104
Source
代碼為:
#include<cstdio>#include<cstring>#include<iostream>#define mod 9937using namespace std;int dp[80+10][10000+10];void init(){ memset(dp,0,sizeof(dp)); dp[1][0]=1; dp[2][1]=2; for(int i=3;i<=81;i++) for(int j=1;j<=10001;j++) { if(j>=2) dp[i][j]=(dp[i-1][j-2]*(i-2))%mod; if(j>=1) dp[i][j]=(dp[i][j]+dp[i-1][j-1]*2)%mod; }}int main(){ int n,m; init(); while(~scanf("%d%d",&n,&m)) { if(n==0&&m==0) return 0; cout<<dp[n][m]<<endl; } return 0;}