Topcoder SRM 584 DIV1 600
思路太繁琐了 ,实在不想解释了
代码:
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<vector>
#include<algorithm>
#include<queue> #define ull unsigned long long
#define ll long long
#define lint long long
using namespace std; const int INF=0x3f3f3f3f;
const int N=53;
ll c[N][N];
ll dp[N][N][N];
ll dp1[N][N][N];
class Excavations
{
public:
long long count(vector <int> kind, vector <int> depth, vector <int> found, int K)
{
memset(c,0,sizeof(c));
for(int i=0;i<N;++i)
for(int j=0;j<=i;++j)
if(j==0||i==j)
c[i][j]=1;
else
c[i][j]=c[i-1][j]+c[i-1][j-1];
int n=kind.size();
int m=found.size(); set<int>st;
for(int i=0;i<n;++i)
st.insert(depth[i]);
int dep=1;
for(set<int>::iterator it=st.begin();it!=st.end();++it,++dep)
{
for(unsigned int i=0;i<depth.size();++i)
if((*it)==depth[i])
depth[i]=dep;
}
sort(found.begin(),found.end());
vector<int>f[N];
for(int i=0;i<m;++i)
{
for(int j=0;j<n;++j)
if(kind[j]==found[i])
f[i].push_back(depth[j]);
sort(f[i].begin(),f[i].end());
}
memset(dp,0,sizeof(dp));
dp[0][0][0]=1;
for(int i=0;i<m;++i)
for(int d=0;d<=n;++d)
for(int w=0;w<K;++w)
if(dp[i][d][w]>0)
{
for(unsigned int l=0;l<f[i].size();++l)
{
for(int x=0;x<=l&&w+x+1<=K;++x)
{
dp[i+1][max(d,f[i][l])][w+x+1]+=dp[i][d][w]*c[l][x];
}
}
}
bool fd[N];
memset(fd,false,sizeof(fd));
for(int i=0;i<m;++i)
fd[found[i]]=true;
vector<int>vd;
int h=0;
for(int i=0;i<n;++i)
if(!fd[kind[i]])
{
vd.push_back(depth[i]);
h=max(h,depth[i]);
}
sort(vd.begin(),vd.end());
int ln=vd.size();
memset(dp1,0,sizeof(dp1));
dp1[ln][n+1][0]=1;
for(int i=ln;i>0;--i)
for(int d=1;d<=n+1;++d)
for(int w=0;w<=ln;++w)
if(dp1[i][d][w])
{
dp1[i-1][d][w]+=dp1[i][d][w];
dp1[i-1][vd[i-1]][w+1]+=dp1[i][d][w];
}
ll s[N]={0};
for(int i=0;i<n;++i)
if(fd[kind[i]])
{
for(int j=1;j<=depth[i];++j)
s[j]++;
}
ll sum=0;
for(int d=2;d<=n+1;++d)
for(int w=0;w<=ln;++w)
if(dp1[0][d][w])
{
for(int d1=1;d1<d;++d1)
for(int w1=1;w1+w<=K;++w1)
if(dp[m][d1][w1])
{
if(s[d]>=K-w1-w)
{
sum+=(dp1[0][d][w]*dp[m][d1][w1]*c[s[d]][K-w-w1]);
}
}
}
return sum;
}
};
Topcoder SRM 584 DIV1 600的更多相关文章
- Topcoder SRM 643 Div1 250<peter_pan>
Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...
- Topcoder Srm 726 Div1 Hard
Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...
- TopCoder SRM 722 Div1 Problem 600 DominoTiling(简单插头DP)
题意 给定一个$12*12$的矩阵,每个元素是'.'或'X'.现在要求$1*2$的骨牌铺满整个矩阵, 'X'处不能放置骨牌.求方案数. 这道题其实和 Uva11270 是差不多的,就是加了一些条件. ...
- SRM 146 DIV1 600
Problem Statement Masterbrain is a two player board game in which one player decides on a secre ...
- topcoder srm 714 div1
problem1 link 倒着想.每次添加一个右括号再添加一个左括号,直到还原.那么每次的右括号的选择范围为当前左括号后面的右括号减去后面已经使用的右括号. problem2 link 令$h(x) ...
- topcoder srm 738 div1 FindThePerfectTriangle(枚举)
Problem Statement You are given the ints perimeter and area. Your task is to find a triangle wi ...
- Topcoder SRM 602 div1题解
打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...
- Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串
Problem Statement The Happy Letter game is played as follows: At the beginning, several players ...
- TopCoder SRM 605 DIV1
604的题解还没有写出来呢.先上605的. 代码去practice房间找. 说思路. A: 贪心,对于每个类型的正值求和,如果没有正值就取最大值,按着求出的值排序,枚举选多少个类型. B: 很明显是d ...
随机推荐
- [转载] linux cgroup
原文: http://coolshell.cn/articles/17049.html 感谢左耳朵耗子的精彩文章. 前面,我们介绍了Linux Namespace,但是Namespace解决的问题主要 ...
- (三)stm32之串口通信DMA传输完成中断
一.DMA功能简介 首先唠叨一下DMA的基本概念,DMA的出现大大减轻了CPU的工作量.在硬件系统中,主要由CPU(内核).外设.内存(SRAM).总线等结构组成,数据经常要在内存和外设之间,外设和外 ...
- maven相关资料
http://www.yiibai.com/maven/ Maven教程 https://www.zhihu.com/question/20104270 http://huangnx.com/tags ...
- Java 默认/缺省 server 还是 client 模式
不多说,复制官方文档,适用于 Java 5 6 7 Architecture OS Default client VM if server-class, server VM; otherwise, c ...
- 转!!!Mybatis实现数据的增删改查(CRUD)
什么是 MyBatis? MyBatis 是支持普通 SQL 查询,存储过程和高级映射的优秀持久层框架. MyBatis 消除了几乎所有的 JDBC 代码和参数的手工设置以及对结果集的检索.MyBat ...
- eclipse设置字体、背景(豆绿)色、自动提示
背景色:(护眼豆绿色) window-->preferences-->General-->Editors-->Text Editors-->(最下遍一栏中的)Backgr ...
- html 实体 => htmlspecialchars
因为没有办法判断用户输入的数据是否安全, 可能含有和sql语句相冲突的字符,比如 ' " < >,那就有一个办法, 把这些特殊字符处理一下,比如吧空格符号变成 ,这样sql语句 ...
- vs2010配置OpenCV2.4.7详细步骤
vs2010配置opencv2.4.7 需要注意:opencv里x86的vc10对应vs2010版本,vc11对应vs2012版本,vc12对应vs2013及以上版本,若vs2013版本的软件配置时选 ...
- phalcon: 查找记录(Finding Records)可用的查询设置如下:
可用的查询设置如下: 参数 描述 举例 conditions Search conditions for the find operation. Is used to extract only tho ...
- Eclipse远程调试出现“JDWP Transport dt_socket failed to initialize”的解决方案
欢迎关注我的社交账号: 博客园地址: http://www.cnblogs.com/jiangxinnju/p/4781259.html GitHub地址: https://github.com/ji ...