这道题用n方的算法会很好做

我一开始想的是nlogn的算法求方案数,

然后没有什么想法(实际上也可以做,但是我太弱了)
我们就可以根据转移方程来推方案数,只是把max改成加,很多动规题

都是这样,比如背包的方案数。


设f[i]为以i为结尾的方案数

当 b[j] + 1 == b[i] 且 a[j] > a[i]时,f[i] 加上f[j]

同时要去重,当b[i] == b[j] 且 a[i] == a[j]时,f[i]为0

另外int最大范围是2^31-1,按理来说这道题应该开longlong,但是可以ac,

说明数据比较弱。但是以后做其他题还是要注意

总结一波

int范围  -2^31 ~ 2^31-1

unsigned int 0 ~ 2 ^ 32 - 1

long long 范围  -2^63 ~ 2^63-1

unsigned long long 范围 0 ~ 2^64-1

#include<cstdio>
#include<algorithm>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
using namespace std; const int MAXN = 5123;
int a[MAXN], b[MAXN], f[MAXN], n; bool cmp(int a, int b)
{
return a > b;
} int main()
{
scanf("%d", &n);
REP(i, 0, n) scanf("%d", &a[i]); int ans1 = 0, ans2 = 0;
REP(i, 0, n)
{
b[i] = 1;
REP(j, 0, i)
if(a[i] < a[j])
b[i] = max(b[i], b[j] + 1);
ans1 = max(ans1, b[i]);
} REP(i, 0, n)
{
if(b[i] == 1) f[i] = 1;
REP(j, 0, i)
{
if(b[j] + 1 == b[i] && a[j] > a[i])
f[i] += f[j];
else if(b[i] == b[j] && a[i] == a[j])
f[i] = 0;
}
if(b[i] == ans1) ans2 += f[i];
}
printf("%d %d\n", ans1, ans2); return 0;
}

最新文章

  1. 【Java EE 学习 76 上】【数据采集系统第八天】【角色授权】【用户授权】【权限的粗粒度控制】【权限的细粒度控制】
  2. 51nod百度之星2016练习赛
  3. Oracle创建/删除表空间和用户(2014-3-10 记)
  4. Oracle 11g 中恢复管理器RMAN介绍
  5. easyui的页面等待提示层,即mask
  6. CentOS下更新python版本
  7. Ventuz配置Leap Motion环境
  8. C#向文件写、读数据
  9. [译]Stairway to Integration Services Level 4 - 增量更新数据
  10. CF 439D(251D题)Devu and his Brother
  11. BZOJ3033太鼓达人——哈密顿回路/欧拉回路
  12. Kubernetes---Pod的扩容和缩容
  13. 解决在vscode中eslint在vue后缀文件中保存时无法自动格式化的问题
  14. ThinkPhp 更改 BIT 类型的问题
  15. 2013级计算机学院数字媒体专业李成梁(笛卡尔积,概率树状图)&amp; 学生选课
  16. postgresql-定时备份,压缩备份
  17. Hibernate 注释用法
  18. tensorflow里面共享变量、name_scope, variable_scope等如何理解
  19. JS截图(html2canvas)
  20. 使用Logstash同步数据至Elasticsearch,Spring Boot中集成Elasticsearch实现搜索

热门文章

  1. C#post调用接口并上传文件
  2. QT笔记 -- (5) 实现QWidget的paintEvent函数,在widget上画背景图形
  3. php查询字符串是否存在 strpos
  4. NOIp2018模拟赛三十五
  5. 【转载】spring boot 链接 虚拟机(Linux) redis
  6. vue父子组件通信传值
  7. vue-cli解析
  8. 嵌入式(C)笔试题
  9. Raw-OS源代码分析之任务删除与总结
  10. C++ 数字、string 简便互转