【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
 

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
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 <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b > a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b < a)a = b; }
const int N = 1010, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;
template <class T1, class T2>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<n;i++)
#define per(i,a,n) for (int i=n-1;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<int> VI;
	typedef long long ll;
	typedef pair<int, int> 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<int> 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)<SZ(B) + m) C.pb(0);
					rep(i, 0, SZ(B)) C[i + m] = (C[i + m] + c*B[i]) % mod;
					L = n + 1 - L; B = T; b = d; m = 1;
				}
				else {
					ll c = mod - d*powmod(b, mod - 2) % mod;
					while (SZ(C)<SZ(B) + m) C.pb(0);
					rep(i, 0, SZ(B)) C[i + m] = (C[i + m] + c*B[i]) % mod;
					++m;
				}
			}
			return C;
		}
		int gao(VI a, ll n) {
			VI c = BM(a);
			c.erase(c.begin());
			rep(i, 0, SZ(c)) c[i] = (mod - c[i]) % mod;
			return solve(n, c, VI(a.begin(), a.begin() + SZ(c)));
		}
	};

	int solve(int n)
	{
		return linear_seq::gao(VI{ 1,4,12,33,88,232,609,1596,4180,10945 }, n);
	}
}
void table()
{
	fib[0] = 0; fib[1] = 1;
	for (int i = 2; i <= 30; ++i)
	{
		fib[i] = fib[i - 1] + fib[i - 2];
	}
	f[0][0] = 1;
	for (int i = 0; i <= 20; ++i)
	{
		for (int k = 0; k <= 30; ++k)
		{
			f[i + 1] |= (f[i] << fib[k]);
		}
		for (int j = 1; j < 100000; ++j)if (!f[i][j])
		{
			printf("%d %d\n", i, j);
			break;
		}
	}
}
int main()
{
	table();
	while(~scanf("%d", &K))
	{
		printf("%d\n", DU::solve(K));
	}
	return 0;
}
/*
【trick&&吐槽】


【题意】
输入一个K(1e9)范围的数,让你求出,无法用K个斐波那契数表示的最小整数。

【分析】


【时间复杂度&&优化】


【数据】
1	1	2	3	5	8	13	21	34	55	89
        _       _       _       _       _
1	4	12	33	88	232	609

*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值