Lightoj_1422
2024-06-29 02:06:41
题目:
求最小要多少件衣服
思路
初始化dp[i][i] = 1;
枚举长度{枚举开头{if(a[j] == a[L] 继承dp[j][L - 1]); dp[j][L]取min forever}};
ACcode
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>using namespace std;
const int inf = 0x3f3f3f3f;int t,n;
int dp[105][105],a[105];int main()
{scanf("%d",&t);for(int T = 1;T <= t; T++){scanf("%d",&n);for(int i = 1;i <= n; i++) scanf("%d",&a[i]);for(int i = 1;i <= n; i++){for(int j = 1;j <= n; j++){dp[i][j] = inf;if(i == j) dp[i][j] = 1;}}for(int i = 2;i <= n; i++){//枚举长度for(int j = 1;j + i - 1 <= n; j++){//枚举开头int L = j + i - 1;if(a[j] == a[L]) dp[j][L] = dp[j][L - 1];for(int f = j;f < L; f++){dp[j][L] = min(dp[j][L],dp[j][f] + dp[f + 1][L]);}}}printf("Case %d: %d\n",T,dp[1][n]);}
}
Lightoj_1422相关推荐
最新文章
- Linux上安装jdk8
- springDataJpa实现普通模糊查询
- 网络协议基础:ARP简析
- leetcode 688. Knight Probability in Chessboard | 688. “马”在棋盘上的概率(dp,记忆化搜索)
- windows服务器apache+PHP+Mysql
- Oracle-1 / Oracle及PlsqlDeveloper的设置
- apch连接mysql数据库连接_配置phpmyadmin连接远程 MySQL数据库
- 深入浅出学习CAN系列-了解CAPL编程语言
- 系统架构设计师:分布式系统(中间件技术)
- [转载] 使用Bugzilla,你肯定会遇到的坑。
- [转载] 网络硬件发展史
- java17的下载与安装
- 错误The server cannot or will not process the request due to something that is perceived to be a clien
- 计算机计时器原理,定时器和计数器-微机原理与接口技术.DOC
- 魔术师usm安装服务器系统,魔术师u盘一键装系统
- 斯坦福大学开源用于网络神经百万量级OGB基准测试的数据集
- verilog赋多位值_verilog中的default应该赋什么样的值
- NEXTCHIP-图像优化师
- 原创短视频推广方式有哪些
- exchange 2010 脱机地址簿操作