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 ...
随机推荐
- ajax请求成功或失败的参数
success:function(response, status, xhr){ }, error:function(xhr, errorText, errorType){ alert(errorTe ...
- PHP 迭代器模式
迭代器:类继承PHP的Iterator接口,批量操作. 1. 迭代器模式,在不需要了解内部实现的前提下,遍历一个聚合对象的内部元素.2. 相比传统的编程模式,迭代器模式可以隐藏遍历元素的所需操作.接口 ...
- TextView使用SpannableString设置复合文本
TextView通常用来显示普通文本,但是有时候需要对其中某些文本进行样式.事件方面的设置.Android系统通过SpannableString类来对指定文本进行相关处理,具体有以下功能: 1.Bac ...
- poj2975(nim游戏取法)
求处于必胜状态有多少种走法. if( (g[i]^ans) <= g[i]) num++; //这步判断很巧妙 // // main.cpp // poj2975 // // Created b ...
- 数据字典 dba_free_space及相对文件号RELATIVE_FNO 小结
1.1 dba_free_space 1.1.1 概述 SQL> desc dba_free_space; Name Type Nullable Default Comments ------- ...
- 20160808_Linux服务
1. http://bbs.csdn.net/topics/370100269 2. http://blog.csdn.net/csfreebird/article/details/8239933 h ...
- 为什么要baidu/Google问题 尽量少在群里问问题
群里问也是可以的 但是 不能指望群里的人详细的回答 有时候的回答会很到位 但是 也可以 应该更多的去网络上搜索信息 因为 那是别人已经写好的 我们为什么不顺便去获取呢 别人花费了精力 我们要尽量运用 ...
- matlab灰度变彩色+白平衡算法实现
% matlab彩色图像分离通道并合并成处理后的彩色图像(彩色变灰度再变彩色) % 白平衡算法(灰度世界法)消除RGB受光照影响 clear all; close all; %读入原始图像 srcIm ...
- 在腾讯云上创建您的SQL Cluster(2)
版权声明:本文由李斯达原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/248 来源:腾云阁 https://www.qclo ...
- crontab在一秒内刷新多次导致部分脚本不生效的问题分析
版权声明:本文由康中良原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/182 来源:腾云阁 https://www.qclo ...