Fzu 2200 Cleaning dp+ pretreatment

Source: Internet
Author: User
Tags printf time limit
Problem 2200 Cleaning accept:10 submit:11
Time limit:1000 mSec Memory limit:65536 KB
problem Description

n people in a circle in the discussion of the big sweep of things, need to elect the K-man. But everyone has a contradiction with his distance of 2 people, so the distance of any two of the K-man cannot be 2, and they want to know how many methods there are. Input

The first line contains a number T (t<=100), which indicates the number of test data.

Next, there are two numbers n,k,n for each line, and K indicates the number of people needed (1<=n<=1000,1<=k<=n). Output

The output satisfies the test instructions scheme number, the scheme number is very large, so please output the program number mod 1,000,000,007 result. Sample Input 3 sample Output 416


Links: http://acm.fzu.edu.cn/problem.php?pid=2200

Practice: DP One-dimensional, the first few people, the second dimension is already selected several people, the third dimension is the current state, 0 means the current this is not selected, the previous one did not choose, 1 said the current this did not choose, the former one selected, 2,3 similar.
Enumerates the States at the beginning of the two, and then preprocess the DP, and when processed to i+2, if the state is the same as the start enumeration, add the value into Real[i]. The preprocessing of Real is the final answer.

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include < malloc.h> #include <ctype.h> #include <math.h> #include <string> #include <iostream> #
Include <algorithm> using namespace std; #include <stack> #include <queue> #include <vector> #include <deque> #include <set> # 
Include <map> #define LL Long long//try ll dp[1010][1010][4];//number ll real[1010][1010];
ll mod = 1000000007;
	void Init () {memset (real,0,sizeof real);
			for (int i=0;i<2;i++)//1 {for (int j=0;j<2;j++)//2 {memset (dp,0,sizeof DP);

			Dp[2][0][i+j*2]=1;
					for (int ii=3;ii<=1002;ii++)//position {for (int jj=0;jj<=ii+2;jj++)//number of {for (int a=0;a<4;a++)//Previous 

						{if ((a&2) ==0) dp[ii][jj][0]= (Dp[ii][jj][0]+dp[ii-1][jj][a])%mod;

						if ((a&2)) dp[ii][jj][1]= (Dp[ii][jj][1]+dp[ii-1][jj][a])%mod; if ((a&1) ==0&& (a&2) ==0&amP;&AMP;JJ) dp[ii][jj][2]= (Dp[ii][jj][2]+dp[ii-1][jj-1][a])%mod;
					if ((a&1) ==0&& (a&2) &&jj) dp[ii][jj][3]= (Dp[ii][jj][3]+dp[ii-1][jj-1][a])%mod; } for (int a=0;a<4;a++) {if ((a^ (i+j*2)) ==0)//and initial state no difference {real[ii-2][jj]= (REAL[II-2][JJ]+DP [II] [JJ] [A])
							%mod;
						if (Dp[ii][jj][a])//int kkk=0;
				}}//if (i==0&&j==0)//printf ("II%d JJ%d DP%d \ n", II,JJ,REAL[II][JJ]);
	}}}}} int main () {init ();
	int t;
	scanf ("%d", &t);
		while (t--) {int n,kk;
		scanf ("%d%d", &AMP;N,&AMP;KK);//int ans=0;
		 


	printf ("%i64d\n", real[n][kk]%mod);
} return 0; }



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.