【HDU6197 2017 ACM ICPC Asia Regional Shenyang Online D】【LIS 最长不下降序列】array array array 数列删除恰好K个数,使得恰好

array array array

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 233    Accepted Submission(s): 141


Problem Description
One day, Kaitou Kiddo had stolen a priceless diamond ring. But detective Conan blocked Kiddo's path to escape from the museum. But Kiddo didn't want to give it back. So, Kiddo asked Conan a question. If Conan could give a right answer, Kiddo would return the ring to the museum. 
Kiddo: "I have an array  A and a number  k, if you can choose exactly  k elements from  A and erase them, then the remaining array is in non-increasing order or non-decreasing order, we say  A is a magic array. Now I want you to tell me whether  A is a magic array. " Conan: "emmmmm..." Now, Conan seems to be in trouble, can you help him?
 

Input
The first line contains an integer T indicating the total number of test cases. Each test case starts with two integers  n and  k in one line, then one line with  n integers:  A1,A2An.
1T20
1n105
0kn
1Ai105
 

Output
For each test case, please output "A is a magic array." if it is a magic array. Otherwise, output "A is not a magic array." (without quotes).
 

Sample Input

3 4 1 1 4 3 7 5 2 4 1 3 1 2 6 1 1 4 3 5 4 6
 

Sample Output

A is a magic array. A is a magic array. A is not a magic array.
 

Source
2017 ACM/ICPC Asia Regional Shenyang Online
 

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x, y) memset(x, y, sizeof(x))
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template inline void gmax(T1 &a, T2 b) { if (b > a)a = b; }
template inline void gmin(T1 &a, T2 b) { if (b < a)a = b; }
const int N = 1010, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;
template inline void gadd(T1 &a, T2 b) { a = (a + b) % Z; }
int casenum, casei;
int K;
int fib[N];
bitset<100010>f[24];
namespace DU
{
#define rep(i,a,n) for (int i=a;i=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
	typedef vector VI;
	typedef long long ll;
	typedef pair PII;
	const ll mod = 998244353;
	ll powmod(ll a, ll b) 
	{ 
		ll res = 1; a %= mod; 
		//assert(b >= 0); 
		for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }
		return res; 
	}
	// head

	int _, n;
	namespace linear_seq {
		const int N = 10010;
		ll res[N], base[N], _c[N], _md[N];

		vector Md;
		void mul(ll *a, ll *b, int k) {
			rep(i, 0, k + k) _c[i] = 0;
			rep(i, 0, k) if (a[i]) rep(j, 0, k) _c[i + j] = (_c[i + j] + a[i] * b[j]) % mod;
			for (int i = k + k - 1; i >= k; i--) if (_c[i])
				rep(j, 0, SZ(Md)) _c[i - k + Md[j]] = (_c[i - k + Md[j]] - _c[i] * _md[Md[j]]) % mod;
			rep(i, 0, k) a[i] = _c[i];
		}
		int solve(ll n, VI a, VI b) { // a 系数 b 初值 b[n+1]=a[0]*b[n]+...
									  //        printf("%d\n",SZ(b));
			ll ans = 0, pnt = 0;
			int k = SZ(a);
			//assert(SZ(a) == SZ(b));
			rep(i, 0, k) _md[k - 1 - i] = -a[i]; _md[k] = 1;
			Md.clear();
			rep(i, 0, k) if (_md[i] != 0) Md.push_back(i);
			rep(i, 0, k) res[i] = base[i] = 0;
			res[0] = 1;
			while ((1ll << pnt) <= n) pnt++;
			for (int p = pnt; p >= 0; p--) {
				mul(res, res, k);
				if ((n >> p) & 1) {
					for (int i = k - 1; i >= 0; i--) res[i + 1] = res[i]; res[0] = 0;
					rep(j, 0, SZ(Md)) res[Md[j]] = (res[Md[j]] - res[k] * _md[Md[j]]) % mod;
				}
			}
			rep(i, 0, k) ans = (ans + res[i] * b[i]) % mod;
			if (ans<0) ans += mod;
			return ans;
		}
		VI BM(VI s) {
			VI C(1, 1), B(1, 1);
			int L = 0, m = 1, b = 1;
			rep(n, 0, SZ(s)) {
				ll d = 0;
				rep(i, 0, L + 1) d = (d + (ll)C[i] * s[n - i]) % mod;
				if (d == 0) ++m;
				else if (2 * L <= n) {
					VI T = C;
					ll c = mod - d*powmod(b, mod - 2) % mod;
					while (SZ(C)


你可能感兴趣的:(题库-HDU,动态规划-线性DP)