$HDOJ5542\ The\ Battle\ of\ Chibi$ 数据结构优化$DP$
$Code$
#include<bits/stdc++.h>
#define il inline
#define Rg register
#define go(i,a,b) for(Rg int i=a;i<=b;i++)
#define yes(i,a,b) for(Rg int i=a;i>=b;i--)
#define mem(a,b) memset(a,b,sizeof(a));
#define int long long
using namespace std;
il int read()
{
int x=,y=;char c=getchar();
while(c<''||c>''){if(c=='-')y=-;c=getchar();}
while(c>=''&&c<=''){x=(x<<)+(x<<)+c-'';c=getchar();}
return x*y;
}
const int N=,mod=(1e9)+;
int T,n,n1,m,as,a[N],b[N],v[N],c[N],f[N][N];
il int Find(int x){return find(b+,b+n1+,x)-b;}//find(b+1,b+n1+1,x)-b;}
il int lowbit(int x){return x&(-x);}
il void add(int p,int w){while(p<=n1){c[p]=(c[p]+w)%mod;p+=lowbit(p);}}
il int sum(int p){int ret=;while(p){ret=(ret+c[p])%mod;p-=lowbit(p);}return ret%mod;}
main()
{
T=read();
go(TT,,T)//remember to init
{
n=read(),m=read();
go(i,,n)a[i]=b[i]=read();
sort(b+,b+n+);
n1=unique(b+,b+n+)-(b+);
go(i,,n){v[i]=Find(a[i]);}
f[][]=;
go(i,,m)
{
mem(c,);if(i==)add(,);
go(j,,n)f[i][j]=sum(v[j]),add(v[j]+,f[i-][j]);
}
as=;go(i,,n)as=(as+f[m][i])%mod;
printf("Case #%lld: %lld\n",TT,as);
}
return ;
}
随机推荐
- deepin 安装golang protobuf
1.安装库文件protobuf,地址:https://github.com/protocolbuffers/protobuf/releases 我电脑是deepin 64位的,所以我直接下载https ...
- 洛谷P1507 NASA的食物计划
//二维费用背包 #include<bits/stdc++.h> using namespace std; ; ; ; int v1[maxn],v2[maxn],w[maxn],n,v1 ...
- 模板—e-dcc缩点
int dfn[MAXN],low[MAXN],cnt; bool isbridge[MAXN]; void tarjan(int x,int edg) { low[x]=dfn[x]=++cnt; ...
- 关于react-router 路径改变页面没有刷新
routert.js 中: <Router> <Switch> <Route exact path="/" component={Login}> ...
- 检查进程启动情况,开始时间、启动时间、启动进程数、进程数是否正确、PID
#!/bin/sh bin=$(cd ``;pwd) cd ${bin} ### 定义检查函数 chk(){ programName=$ correctNum=$ programSubName=$ # ...
- Oracle数据字典全解
一.概念: 1.数据字典(data dictionary)是 Oracle 数据库的一个重要组成部分,这是一组用于记录数据库信息的只读(read-only)表. 数据字典里存有用户信息.用户的权限信息 ...
- oracle 减少对表的查询
在含有子查询的SQL语句中,要特别注意减少对表的查询. 例如: 低效 SELECT TAB_NAME FROM TABLES WHERE TAB_NAME = ( SELECT TAB_NAME FR ...
- BERT大火却不懂Transformer?读这一篇就够了 原版 可视化机器学习 可视化神经网络 可视化深度学习
https://jalammar.github.io/illustrated-transformer/ The Illustrated Transformer Discussions: Hacker ...
- 2018年NOIP普及组复赛题解
题目涉及算法: 标题统计:字符串入门题: 龙虎斗:数学题: 摆渡车:动态规划: 对称二叉树:搜索. 标题统计 题目链接:https://www.luogu.org/problem/P5015 这道题目 ...
- 【codeforces 520A】Pangram
[题目链接]:http://codeforces.com/problemset/problem/520/A [题意] 给你一个字符串. 统计里面有没有出现所有的英文字母->'a'..'z' 每个 ...
