250  想想就发现规律了。

500  暴力,括号匹配。

1000

给一个f数组,如果i存在,那么f[i]也得存在,问这样的集合有多少种。

先拓扑一下,dp[i] = mul(dp[son]+1)最后环里面的元素的乘积是结果。

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
using namespace std;
#define LL long long
int p[][],o[],flag[],nt[];
LL dp[];
LL temp;
void dfs(int x)
{
flag[x] = ;
temp *= dp[x];
if(flag[nt[x]] == )
return ;
flag[nt[x]] = ;
dfs(nt[x]);
}
class InvariantSets
{
public :
LL countSets(vector <int> f)
{
int i,j,n,z;
LL ans = ;
n = f.size();
for(i = ;i < n;i ++)
{
p[i][f[i]] = ;
dp[i] = ;
nt[i] = f[i];
o[f[i]] ++;
}
for(;;)
{
z = ;
for(i = ;i < n;i ++)
{
if(o[i] == &&!flag[i])
{
flag[i] = ;
z = ;
for(j = ;j < n;j ++)
{
if(p[i][j] == &&!flag[j])
{
dp[j] *= (dp[i] + );
o[j] --;
}
}
}
}
if(!z) break;
}
for(i = ;i < n;i ++)
{
temp = ;
if(flag[i] == )
{
dfs(i);
ans *= (temp+);
}
}
return ans;
}
};

SRM 628 DIV2的更多相关文章

  1. topcoder SRM 628 DIV2 BracketExpressions

    先用dfs搜索所有的情况,然后判断每种情况是不是括号匹配 #include <vector> #include <string> #include <list> # ...

  2. topcoder SRM 628 DIV2 BishopMove

    题目比较简单. 注意看测试用例2,给的提示 Please note that this is the largest possible return value: whenever there is ...

  3. topcoder srm 628 div2 250 500

    做了一道题,对了,但是还是掉分了. 第二道题也做了,但是没有交上,不知道对错. 后来交上以后发现少判断了一个条件,改过之后就对了. 第一道题爆搜的,有点麻烦了,其实几行代码就行. 250贴代码: #i ...

  4. SRM 628 D1L3:DoraemonPuzzleGame,math,后市展望,dp

    称号:c=problem_statement&pm=13283&rd=16009">http://community.topcoder.com/stat?c=probl ...

  5. SRM 657 DIV2

    -------一直想打SRM,但是感觉Topcoder用起来太麻烦了.题目还是英文,不过没什么事干还是来打一打好了.但是刚注册的号只能打DIV2,反正我这么弱也只适合DIV2了.. T1: 题目大意: ...

  6. Topcoder Srm 673 Div2 1000 BearPermutations2

    \(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...

  7. Topcoder Srm 671 Div2 1000 BearDestroysDiv2

    \(>Topcoder \space Srm \space 671 \space Div2 \space 1000 \space BearDestroysDiv2<\) 题目大意 : 有一 ...

  8. 记第一次TopCoder, 练习SRM 583 div2 250

    今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...

  9. Topcoder srm 632 div2

    脑洞太大,简单东西就是想复杂,活该一直DIV2; A:水,基本判断A[I]<=A[I-1],ANS++; B:不知道别人怎么做的,我的是100*N*N;没办法想的太多了,忘记是连续的数列 我们枚 ...

随机推荐

  1. UITableViewCell 的附件类型 accessoryType 选中、详情、箭头

    UITableViewCell * cell = [[UITableViewCell alloc] init]; 设置cell的附件类型: // >1 打钩 选中//    cell.acces ...

  2. AndroidStudio非法字符: '\ufeff'解决

    一. 问题解决办法 在昨天,帮助同学把他的Android项目从eclipse迁移到Android Studio上面的时候,编译时,Android Studio报了一个错误, ***.java Erro ...

  3. string类型转换int类型

    C++转换形式(C++11): int main(int argc, char* argv[]) { std::"; std::string str2 = "3.14159&quo ...

  4. ssh配置git clone简易流程

    1. 生成密钥 ssh-keygen -t rsa -C "jaynaruto@qq.com" //如果只有一对密钥,建议不要修改默认的密钥名称,即一直按回车即可 此命令会在你当前 ...

  5. SWFUpload多图上传、C#后端跨域传文件带参数

    前几天工作中用到了SWFUpload上传图片,涉及到跨域,因为前端无法实现跨域,所以只能把文件传到后端进行跨域请求,整理分享下. 效果图 前端 html部分 <!DOCTYPE html> ...

  6. 使用httpclient 调用selenium webdriver

    结合上次研究的selenium webdriver potocol ,自己写http request调用remote driver代替selenium API selenium web driver ...

  7. FreeCodeCamp心得

    <img>    <input>  tags are self-closing. So that there is only one tag without a slash i ...

  8. iOS 内存管理

    一 . 内存管理 包括内存分配 和 内存清除 1.内存管理的范围 :人和继承于NSObject类的对象都需要进行内存管理,任何非对象类型的对象(基本数据类型 如 int char float doub ...

  9. sh 测试网段在线主机

    yum install nmap nmap -sP  192.168.21.1/24 查看网段在线主机 grep -vwf file1 file2 文件内容比较 #!/bin/bash # day=` ...

  10. sh5.while 脚本练习

    脚本编程: 顺序结构 选择结构 if, case 循环结构 for,while,until while循环:适用于循环次数未知的场景 语法: while CONDITION;do statement ...