• URAL1696 Salary for Robots


    题目戳这里
    最长下降子序列单调队列求法。
    (f_{i,j,k})表示考虑前(i)个数,(g_1 = j,g_2 = k)的方案数。转移:
    $$f_{i,j,k} = sum_{p = k+1}{j}f_{i-1,p,k}+sum_{p=0}kf_{i-1,j,p}$$
    二维前缀和优化。复杂度(O(NK^2))

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<cstdlib>
    using namespace std;
    
    const int maxk = 201;
    int f[2][maxk][maxk],N,K,rhl,ans;
    
    int main()
    {
    	freopen("1696.in","r",stdin);
    	freopen("1696.out","w",stdout);
    	scanf("%d %d %d",&N,&K,&rhl);
    	for (int i = 1;i <= K;++i) f[1][i][0] = 1;
    	for (int p = 2,now = 0,last = 1,inc;p <= N;++p,swap(now,last))
    	{
    		for (int i = 1;i <= K;++i)
    		{
    			for (int j = i-1;j >= 0;--j)
    			{
    				f[last][i][j] += f[last][i][j+1];
    				if (f[last][i][j] >= rhl) f[last][i][j] -= rhl;
    			}
    			for (int j = 0;j < i;++j)
    			{
    				f[last][i][j] += f[last][i-1][j];
    				if (f[last][i][j] >= rhl) f[last][i][j] -= rhl;
    			}
    		}
    		memset(f[now],0,sizeof f[now]);		
    		for (int i = 1;i <= K;++i)
    			for (int j = 0;j < i;++j)
    			{
    				f[now][i][j] = f[last][i][j]-f[last][j][j]-f[last][i][j+1]+f[last][j][j+1];
    				while (f[now][i][j] >= rhl) f[now][i][j] -= rhl;
    				while (f[now][i][j] < 0) f[now][i][j] += rhl;
    				if (j)
    				{
    					inc = f[last][i][0]-f[last][i-1][0]-f[last][i][j+1]+f[last][i-1][j+1];
    					while (inc >= rhl) inc -= rhl; while (inc < 0) inc += rhl;
    					f[now][i][j] += inc; if (f[now][i][j] >= rhl) f[now][i][j] -= rhl;
    				}
    			}
    	}
    	for (int i = 1;i <= K;++i)
    		for (int j = 0;j < i;++j)
    		{
    			ans += f[N&1][i][j];
    			if (ans >= rhl) ans -= rhl;
    		}
    	printf("%d
    ",ans+1);
    	fclose(stdin); fclose(stdout);
    	return 0;
    }
    
    
  • 相关阅读:
    C#中的接口和类的不同点
    值类型和引用类型的区别?
    时隔两年再次操刀NPOI合并单元格
    二.Docker下安装和运行Mysql
    一.CentOS8下的Docker安装
    .NetCore3.1使用Autofac
    .NET Core 3.1使用Swagger
    数组排序和数组对象排序
    C# 操作Excel , 支持超链接 跳转Sheet 页面,HSSFHyperlink函数
    MVC导入Excel通过NPOI
  • 原文地址:https://www.cnblogs.com/mmlz/p/6403891.html
Copyright © 2020-2023  润新知