zoukankan      html  css  js  c++  java
  • 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;
    }
    
    
  • 相关阅读:
    AS400一些有用的命令
    Publish的时候某些需要用到的文件没deploy上去
    DB2一些SQL的用法
    根据PostgreSQL 系统表查出字段描述
    linux memcached 安装
    CentOS下XEN虚拟服务器安装配置
    Apache the requested operation has failed
    PHP配置兼容ZendDebugger和Optimizer
    虚拟机比较
    memcache 运行情况,内存使用
  • 原文地址:https://www.cnblogs.com/mmlz/p/6403891.html
Copyright © 2011-2022 走看看