思路太繁琐了 ,实在不想解释了

代码:

#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的更多相关文章

  1. Topcoder SRM 643 Div1 250<peter_pan>

    Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...

  2. Topcoder Srm 726 Div1 Hard

    Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...

  3. TopCoder SRM 722 Div1 Problem 600 DominoTiling(简单插头DP)

    题意  给定一个$12*12$的矩阵,每个元素是'.'或'X'.现在要求$1*2$的骨牌铺满整个矩阵, 'X'处不能放置骨牌.求方案数. 这道题其实和 Uva11270 是差不多的,就是加了一些条件. ...

  4. SRM 146 DIV1 600

    Problem Statement      Masterbrain is a two player board game in which one player decides on a secre ...

  5. topcoder srm 714 div1

    problem1 link 倒着想.每次添加一个右括号再添加一个左括号,直到还原.那么每次的右括号的选择范围为当前左括号后面的右括号减去后面已经使用的右括号. problem2 link 令$h(x) ...

  6. topcoder srm 738 div1 FindThePerfectTriangle(枚举)

    Problem Statement      You are given the ints perimeter and area. Your task is to find a triangle wi ...

  7. Topcoder SRM 602 div1题解

    打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...

  8. Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串

    Problem Statement      The Happy Letter game is played as follows: At the beginning, several players ...

  9. TopCoder SRM 605 DIV1

    604的题解还没有写出来呢.先上605的. 代码去practice房间找. 说思路. A: 贪心,对于每个类型的正值求和,如果没有正值就取最大值,按着求出的值排序,枚举选多少个类型. B: 很明显是d ...

随机推荐

  1. [转载] 深入 superviser

    模块简介 新人接触线上的时候一般都会碰到supervise这个工具,导师对这个模块的解释一般就是,这个模块是监控进程,当进程挂掉之后,supervise会将进程启动.这样当进程出 现问题,如因出cor ...

  2. 树的计数 + prufer序列与Cayley公式 学习笔记

    首先是 Martrix67 的博文:http://www.matrix67.com/blog/archives/682 然后是morejarphone同学的博文:http://blog.csdn.ne ...

  3. ajax跨域jsonp

    <!DOCTYPE html><html lang="zh-CN"><head> <meta charset="UTF-8&qu ...

  4. [js]事件综合 整理

    原文链接:http://www.cnblogs.com/xxcanghai/p/5205998.html 事件流:页面接收事件的顺序,IE提出了事件冒泡流,Netscape提出了事件捕获流. 事件冒泡 ...

  5. Subversion中文手册(svnbook) TortoiseSVN中文帮助手册

    文档地址 http://svndoc.iusesvn.com/

  6. scala集合

    优先使用不可变集合.不可变集合适用于大多数情况,让程序易于理解和推断,因为它们是引用透明的( referentially transparent )因此缺省也是线程安全的. 使用可变集合时,明确地引用 ...

  7. phalcon: 缓存片段,文件缓存,memcache缓存

    几种缓存,需要用到前端配置,加后端实例配合着用 片段缓存: public function indexAction() { //渲染页面 $this->view->setTemplateA ...

  8. Unity5中叹为观止的实时GI效果

    http://www.manew.com/thread-43970-1-1.html 今天为大家分享unity与Alex Lovett共同使用unity5制作的Shrine Arch-viz Demo ...

  9. OI中的代码调试

    作为一位OIer,代码调试的能力必不可少. 今天梳理一下自己进行代码调试的方法,下面只是一些个人的总结. 代码的评价有三部分: 正确性 强健性 高效性 检查也应该从这三部分出发. [正确性] 打完代码 ...

  10. Node.js 开发模式(设计模式)

    Asynchronous code & Synchronous code As we have seen in an earlier post (here), how node does th ...