• [luoguP1043] 数字游戏(DP)


    传送门

    搞个前缀和随便DP一下

    代码

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #define N 101
    #define min(x, y) ((x) < (y) ? (x) : (y))
    #define max(x, y) ((x) > (y) ? (x) : (y))
    
    int n, m, ans1 = ~(1 << 31), ans2;
    int a[N], sum[N], f1[N][N][N], f2[N][N][N];
    
    inline int read()
    {
    	int x = 0, f = 1;
    	char ch = getchar();
    	for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    	for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
    	return x * f;
    }
    
    int main()
    {
    	int i, j, k, l;
    	n = read();
    	m = read();
    	for(i = 1; i <= n; i++) a[i] = read(), a[i + n] = a[i];
    	for(i = 1; i < 2 * n; i++) sum[i] = a[i] + sum[i - 1];
    	memset(f1, 127 / 3, sizeof(f1));
    	for(k = 1; k <= m; k++)
    		for(i = 1; i < 2 * n; i++)
    			for(j = i + k - 1; j < 2 * n; j++)
    			{
    				if(k == 1)
    				{
    					f1[i][j][k] = f2[i][j][k] = ((sum[j] - sum[i - 1]) % 10 + 10) % 10;
    					continue;
    				}
    				for(l = i + k - 1; l < j; l++)
    				{
    					f1[i][j][k] = min(f1[i][j][k], f1[i][l][k - 1] * (((sum[j] - sum[l]) % 10 + 10) % 10));
    					f2[i][j][k] = max(f2[i][j][k], f2[i][l][k - 1] * (((sum[j] - sum[l]) % 10 + 10) % 10));
    				}
    			}
    	for(i = 1; i <= n; i++)
    	{
    		ans1 = min(ans1, f1[i][i + n - 1][m]);
    		ans2 = max(ans2, f2[i][i + n - 1][m]);
    	}
    	printf("%d
    %d
    ", ans1, ans2);
    	return 0;
    }
    

      

  • 相关阅读:
    e.target和e.event和event.srcElement
    js代码优化
    史上最全的CSS hack方式一览
    学习NodeJS第一天:node.js引言
    响应式布局
    HTML+CSS编写规范
    英文SEO外部链接资源收集之常用的footprints
    判别木马
    php简单命令代码集锦
    zencart 新页面调用好功能代码集:
  • 原文地址:https://www.cnblogs.com/zhenghaotian/p/7085845.html
Copyright © 2020-2023  润新知