poj 1631 Bridging signals
题目链接:http://poj.org/problem?id=1631
题目分类:动态规划
代码:
#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #include<iostream> using namespace std; #define INF 0x3f3f3f3f int n; int a[50500]; int dp[50500]; int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int t; scanf("%d",&t); while(t--) { memset(a,0,sizeof(a)); scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&a[i]); } fill(dp,dp+n,INF); for(int i=0;i<n;i++) { *lower_bound(dp,dp+n,a[i])=a[i]; } printf("%d\n",lower_bound(dp,dp+n,INF)-dp); } return 0; }
下面的代码是超时的
#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #include<iostream> using namespace std; #define INF 0x3f3f3f3f int n; int a[5050]; int dp[5050]; int main() { freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); int t; scanf("%d",&t); while(t--) { memset(a,0,sizeof(a)); scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); } memset(dp,0,sizeof(dp)); int res=0; for(int i=1;i<=n;i++) { dp[i]=1; for(int j=1;j<i;j++) { if(a[j]<a[i]) { dp[i]=max(dp[i],dp[j]+1); } } res=max(dp[i],res); } printf("%d\n",res); } return 0; }
anytime you feel the pain.hey,refrain.don't carry the world upon your shoulders
分类:
Algorithm
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个我遇到过的“量子力学”级别的BUG。
· Linux系列:如何调试 malloc 的底层源码
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· Apifox不支持离线,Apipost可以!
· 历时 8 年,我冲上开源榜前 8 了!
· Trae 开发工具与使用技巧
· 通过 API 将Deepseek响应流式内容输出到前端
· 上周热点回顾(3.10-3.16)