Problem 2236 第十四个目标
Problem 2236 第十四个目标 Accept: 4 Submit: 6
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
目
暮警官、妃英里、阿笠博士等人接连遭到不明身份之人的暗算,柯南追踪伤害阿笠博士的凶手,根据几起案件现场留下的线索发现凶手按照扑克牌的顺序行凶。在经
过一系列的推理后,柯南发现受害者的名字均包含扑克牌的数值,且扑克牌的大小是严格递增的,此外遇害者与毛利小五郎有关。
为了避免下一个遇害者的出现,柯南将可能遭到暗算的人中的数字按关联程度排列了出来,即顺序不可改变。柯南需要知道共有多少种可能结果,满足受害人名字出现的数字严格递增,但是他柯南要找出关键的证据所在,所以这个任务就交给你了。
(如果你看不懂上面在说什么,这题是求一个数列中严格递增子序列的个数。比如数列(1,3,2)的严格递增子序列有(1)、(3)、(2)、(1,3)、(1,2),共5个。长得一样的但是位置不同的算不同的子序列,比如数列(3,3)的答案是2。)
Input
多组数据(<=10),处理到EOF。
第一行输入正整数N(N≤100 000),表示共有N个人。
第二行共有N个整数Ai(1≤Ai≤10^9),表示第i个人名字中的数字。
Output
每组数据输出一个整数,表示所有可能的结果。由于结果可能较大,对1 000 000 007取模后输出。
Sample Input
1 3 2
Sample Output
Source
福州大学第十三届程序设计竞赛
1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<queue>
6 #include<math.h>
7 using namespace std;
8 typedef long long LL;
9 const int N=1e9+7;
10 LL dp[100005];
11 LL bit[100005];
12 int ak[100005];
13 typedef struct pp
14 {
15 int x;
16 int id;
17 } ss;
18 ss ans[100005];
19 bool cmp(pp n, pp m)
20 {
21 return n.x<m.x;
22 }
23 void add(int i,int x,int n);
24 LL BIT(int i);
25 int main(void)
26 {
27 int i,j ,k;
28 int s;int n;
29 while(scanf("%d",&n)!=EOF)
30 {
31 int m;
32 for(i=1; i<=n; i++)
33 {
34 scanf("%d",&ans[i].x);
35 ans[i].id=i;
36 }
37 sort(ans+1,ans+1+n,cmp);
38 ak[ans[1].id]=1;
39 int cn=1;
40 int dd=ans[1].x;
41 for(i=2; i<=n; i++)
42 {
43 if(dd!=ans[i].x)
44 {
45 cn++;
46 dd=ans[i].x;
47 }
48 ak[ans[i].id]=cn;
49 }
50 memset(bit,0,sizeof(bit));
51 memset(dp,0,sizeof(dp));
52 for(i=1; i<=n; i++)
53 {
54 dp[i]=BIT(ak[i]-1);
55 dp[i]=(dp[i]+1)%N;
56 add(ak[i],dp[i],cn);
57 }
58 LL sum=0;
59 for(i=1; i<=n; i++)
60 {
61 sum=(sum+dp[i])%N;
62 }
63 printf("%lld\n",sum);
64 }
65 return 0;
66 }
67 LL BIT(int i)
68 {
69 LL s=0;
70 while(i>0)
71 {
72 s=(s+bit[i])%N;
73 i-=(i&(-i));
74 }
75 return s;
76 }
77 void add(int i,int x,int n)
78 {
79 while(i<=n)
80 {
81 bit[i]=(bit[i]+x)%N;
82 i+=(i&(-i));
83 }
84 }
Problem 2236 第十四个目标的更多相关文章
- FZu Problem 2236 第十四个目标 (线段树 + dp)
题目链接: FZu Problem 2236 第十四个目标 题目描述: 给出一个n个数的序列,问这个序列内严格递增序列有多少个?不要求连续 解题思路: 又遇到了用线段树来优化dp的题目,线段树节点里 ...
- 第十四个目标(dp + 树状数组 + 线段树)
Problem 2236 第十四个目标 Accept: 17 Submit: 35 Time Limit: 1000 mSec Memory Limit : 32768 KB Probl ...
- hdu6435 Problem J. CSGO标程讲解以及改正标程的一个错误(本来第一个样例过不了2333) 以及 poj2926 五维曼哈顿距离模板
比赛的时候抄poj2926的模板,但改不来啊orz #include <iostream> #include <cstdio> #include <cstring> ...
- 第十四个目标 (fzu)
http://acm.fzu.edu.cn/contest/problem.php?cid=151&sortid=8 Problem Description 目暮警官.妃英里.阿笠博士等人接连 ...
- FZU2236 第十四个目标 dp+树状数组优化
分析:这种题烂大街,n^2,然后数据结构优化下到nlogn,离散化 #include <cstdio> #include <cstring> #include <queu ...
- 《挑战程序设计竞赛》2.4 数据结构-并查集 POJ1182 2236 1703 AOJ2170
POJ1182 http://poj.org/problem?id=1182 题目 难得的中文题... 食物链 Time Limit: 1000MS Memory Limit: 10000K Tota ...
- [LeetCode] The Skyline Problem
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- hdu4975 A simple Gaussian elimination problem.(正确解法 最大流+删边判环)(Updated 2014-10-16)
这题标程是错的,网上很多题解也是错的. http://acm.hdu.edu.cn/showproblem.php?pid=4975 2014 Multi-University Training Co ...
- ACM: A Simple Problem with Integers 解题报告-线段树
A Simple Problem with Integers Time Limit:5000MS Memory Limit:131072KB 64bit IO Format:%lld & %l ...
随机推荐
- Volatile的3大特性
Volatile volatile是Java虚拟机提供的轻量级的同步机制 3大特性 1.保证可见性 当多个线程同时访问同一个变量时,一个线程修改了这个变量的值,其他线程能够立即看得到修改的值 案例代码 ...
- apostrophe
apostrophe 者,', 0x27, 十进制39,ASCII里的single quote (单引号) 也.one of the 'inverted commas'. 在书写上可以表示所有格.省略 ...
- nodejs-Path模块
JavaScript 标准参考教程(alpha) 草稿二:Node.js Path模块 GitHub TOP Path模块 来自<JavaScript 标准参考教程(alpha)>,by ...
- 【leetcode】222. Count Complete Tree Nodes(完全二叉树)
Given the root of a complete binary tree, return the number of the nodes in the tree. According to W ...
- 转 proguard 混淆工具的用法 (适用于初学者参考)
转自:https://www.cnblogs.com/lmq3321/p/10320671.html 一. ProGuard简介 附:proGuard官网 因为Java代码是非常容易反编码的,况且An ...
- Android 高级UI组件(一)GridView与ListView
1.GridView 1.GridView学习 GridView和ListView都是比较常用的多控件布局,而GridView更是实现九宫图的首选 main.xml: <?xml version ...
- 转 Android应用开发必备的20条技能
https://blog.csdn.net/u012269126/article/details/52433237 有些andorid开发人员感觉很迷茫,接下来该去看系统源码还是继续做应用,但是感觉每 ...
- 【Python】【Basic】MacOS上搭建Python开发环境
1. Python3 1.1. 下载地址:https://www.python.org/downloads/mac-osx/ 1.1.1. PKG包安装: 没啥可说的,点点点,下一步而已,不用手动配置 ...
- iOS UIWebview 长按图片,保存到本地相册
我们所要解决的问题如题目所示:ios中,长按Webview中的图片,将图片保存到本地相册.解决方案:对load的html网页,执行js注入,通过在webview中执行js代码,来响应点击事件,通过js ...
- Linux后台启动服务
systemctl 启动/关闭/启用/禁用服务 总结 启动服务 systemctl start test.service 关闭服务 systemctl stop test.service 重启服务 s ...