2017武汉大学校赛网络预选赛b题

09年ACM武汉大学网络赛试题 09年ACM区域赛 网络赛 武汉大学 包括题目(PDF)、测试数据和标程 立即下载

Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 512 mebibytes
When Asuho was just a little girl, she has been loving stars, as there are so many romantic stories about old legends and the stars.

Today, as usual, Asuho went to the observatory with her beloved boyfriend, Kogasaka Ming, to see the splendid sky of galaxy. Sitting with Kogasaka shoulder to shoulder, Asuho thought nothing could make her happier.

“Asuho,” Kogasaka called Asuho softly. “I have a question about the Hoshizora(night sky with stars).”

“What’s it?” Asuho answered, happily. “I know everything about the stories, you can ask anything.”

Kogasaka smiled, “You see the stars? Just imagine there are nn distinct stars in the sky while n-1n−1 relationships connect them. Each relationship is between two stars and all stars are connected directly or indirectly. Now you need to divide the nn stars into mm different types. Beware that no two directly connected stars should share the same type and some stars cannot be some types. I want you to tell me how many distinct solutions there could be.”

Suddenly the Stella meteor shower appeared, so the lovers forgot the question and started to admire the beautiful Hoshizora.

Asuho thought it was unbelievable that Kogasaka should ask her such a foolish question which she can’t solve. Of course she didn’t wish to reveal her poor math. So can you help her to tell the answer?

Input
The Input file contains several test cases.

For each case, the first line contains two integers nn (2\le n\le 10^42≤n≤10
​4
​​ ), mm (1\le m\le 201≤m≤20)

The next n-1n−1 lines, each line contains 2 integers x_ix
​i
​​ , y_iy
​i
​​ expressing relationships between the two stars.

The next nn lines, each lines contains m numbers and each of the mm is 0 or 1.

The ii-th number of the jj-th line respect whether jj-th star can be divided into the ii-th type. 1 means it could while 0 means not.

Output
For each test case, output one single line, containing the number of solutions module 10^7+910
​7
​​ +9
Examples
Input 1
4 6
1 2
1 3
1 4
1 1 1 1 1 0
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
Output 1
625

题意:给你一棵树,给树上每个顶点涂色,相连的顶点颜色不能相同,问你有多少中涂色的方式。

解题思路:树dp,dp[i][j]表示以i为根的子树,i涂上颜色j的种类数。具体思路看代码注释。比赛的时候和队友各种暴力找,还是做的题少了,没有往这方面想。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e4 + 10;
const ll mod = 1e7 + 9;
int n,m;
int c[maxn][30];//第i个点的是否可涂颜色j
vector<int> Tree[maxn];//i的儿子
vector<int> g[maxn];//图的邻接表
ll dp[maxn][30];//dp[i][j] 以顶点i为根的子树,染上颜色j的种类数
bool visit[maxn];
void init()//初始化
{
    memset(visit,false,sizeof(visit));
    for(int i = 1; i <= n; i++)
    {
        Tree[i].clear();
        g[i].clear();
    }
    memset(dp,0,sizeof(dp));
}
void build(int root)
{
    /******************
    题目给定的图是无根树,所以先把这个图转化为一颗以1为根的有根树,便于我们处理
    ******************/
    if(visit[root]) return;
    visit[root] = true;
    for(int i = 0; i < g[root].size(); i++)
    {
        int term = g[root][i];
        if(!visit[term])
        {
            Tree[root].push_back(term);
            build(term);
        }
    }
}
void dfs(int root)
{
    if(Tree[root].size() == 0)//如果节点是叶节点的情况
    {
        for(int i = 1; i <= m; i++)
        {
            if(c[root][i]) dp[root][i] = 1;
            else dp[root][i] = 0;
        }
        return;
    }
    for(int i = 0; i < Tree[root].size(); i++)//先处理子树
    {
        int son = Tree[root][i];
        dfs(son);
    }
    for(int i = 1; i <= m; i++)
    {
        /*************************
        分别计算出每一个dp[root][i],计算的方法为
        1.若c[root][i] == 0,表示root点不能涂i颜色,所以dp[root][i] = 0.
        2.若c[root][i] == 1,表示root点能涂i颜色,所以对于root的每一个儿子,我们
        可以求出res = sum(dp[son][k]),其中k从1~m,但是k != i,因为相连的两点颜色不能相等
        对于每一个儿子,求出的res累乘起来就行。所以dp[root][i] = mul(res[son]),son为root的所有儿子
        *************************/
        if(c[root][i])
        {
            ll sum = 1;
            for(int j = 0; j < Tree[root].size(); j++)
            {
                ll res = 0;
                int son = Tree[root][j];
                for(int k = 1; k <= m; k++)
                {
                    if(k != i)
                    res = (res + dp[son][k])%mod;
                }
                sum = (sum*(res%mod))%mod;
            }
            dp[root][i] = sum;
        }
        else dp[root][i] = 0;

    }
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        init();
        int u,v;
        for(int i = 1; i <= n - 1; i++)
        {
            scanf("%d%d",&u,&v);
            g[u].push_back(v);
            g[v].push_back(u);
        }
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= m; j++)
            {
                scanf("%d",&c[i][j]);
            }
        }
        build(1);
        dfs(1);
        ll ans = 0;
        /*****************
        最后把所有的dp[1][i]加起来就行
        *****************/
        for(int i = 1; i <= m; i++)
        {
            ans = (ans + dp[1][i])%mod;
        }
        printf("%lld\n",ans%mod);
    }
    return 0;
}
/***********
Create by lucky stars
2017 4 10
***********/


武汉大学2018数模校赛题目.rar 是一个有关时间序列的题目,预测一个城市未来天然气的趋势 立即下载

相关推荐

商BC1230年世界历史地图矢量文件SHP格式.zip

本资源为《商BC1230年世界历史地图矢量文件SHP格式》压缩包,文件大小约 18.75 MB,便于集中下载、整理和使用。具体内容请结合压缩包内的实际文件与说明查看。 在当前可读取的目录中,可见属性表(.dbf)、投影说明文件(.prj)、Shapefile 主文件(.shp)、Shapefile 索引(.shx)。建议解压后保持原有目录结构,先浏览文件清单与说明,再选择需要的资料进行加载或整理。 应用方面,可根据实际资料用于学习练习、资料检索、研究整理或项目参考。使用时可先确定所需内容,建立清晰的文件分类,再按项目要求进行筛选、转换与汇总。 使用 Shapefile 数据时,请把实际配套的 .shp、.shx、.dbf 等文件保存在同一目录,并保持同名关联;加载后再检查坐标系与中文字段显示。如需叠加其它数据,请先统一坐标与字段口径。 数据来源、时间范围、坐标系、字段定义、精度和使用条件,请以实际文件及原始说明为准。本介绍不对文件名之外尚未核实的信息作额外承诺。

NYOJ新生赛-早华寅的财富密码

Problem D. 早华寅的财富密码 Input file: standard input Output file: standard output Time limit: 1 second Memory limit: 128 megabytes 早队在睡觉做梦的时候梦到自己发现了一个藏宝图,并根据藏宝图成功找到了宝藏的位置,现在他 在宝藏的入口处,入口的地上散布着一些碎片,好像是宝藏的钥匙,碎片上写着一个个数字,需要你拼成 一个最大的整数才能形成正确的钥匙打开宝藏入口的门,你能帮助早华寅拼好钥匙吗? I

00后的博客 273

【寄存器模型】二、前门访问与后门访问

1.后门访问可以更好的完成前门访问能够完成的事情:后门访问不消耗仿真时间,且消耗的运行时间也远小于前门访问的运行时间。 2.后门访问可以完成前门访问不能完成的事:对于某些特定的场景,如网络通信系统中的一些只读计数器,当要验证计数器进位归零的场景时,前门访问无法完成写寄存器操作,只能通过消耗仿真时间来使计数器到达特定的计数值。而后门访问可以直接对只读寄存器赋一个初值......

carrotbanana的博客 9666

2021-08-09

The 14th Jilin Provincial Collegiate Programming Contest G.Matrix Problem G. Matrix Input file: standard input Output file: standard output Time limit: 1 second Memory limit: 256 megabytes Bob is playing a matrix game. He needs to deal with a matrix of n

apple_52197802的博客 383

STM32 HAL库驱动BMP388:从寄存器配置到高精度气压温度采集

本文详细介绍了如何使用STM32 HAL库驱动BMP388气压温度传感器,实现高精度数据采集。内容涵盖从硬件连接到STM32CubeMX配置、关键寄存器解析、驱动源码编写,到核心补偿算法与海拔换算的完整流程,并提供了针对不同应用场景的优化配置与调试技巧,帮助开发者快速构建稳定可靠的测量方案。

weixin_29299807的博客 179

智能座舱测试工程师必看:从零搭建自动化测试框架的5个实战技巧

本文为智能座舱测试工程师提供从零搭建自动化测试框架的5个实战技巧,涵盖环境搭建、ADB高级应用、Python脚本工程化、Monkey测试优化及性能调优。通过ADB深度操作和Python脚本封装,帮助测试人员构建高可复用的智能座舱测试解决方案,显著提升测试效率与问题发现率。

python9snake的博客 648

2017武汉大学校赛网络预选赛d题

Input file: standard input Output file: standard output Time limit: 1 second Memory limit: 512 mebibytes Every year, the ACM/ICPC team will hold many contests, some of them are training while othe

creatorx的博客 792

使用petalinux做嵌入式设计开发(1)

1.创建vivado工程,建立硬件环境,最终导出hdf文件 既可以在windows系统下的vivado上编写硬件工程并导出hdf文件,也可以在linux系统下的vivado中编写硬件工程并导出hdf文件。(对于windows系统下导出的hdf文件还需要传递到linux系统下的文件夹中。) 2.以hdf硬件文件为基础创建,配置,编译,打包petalinux工程,导出linux系统所需镜像文件。 具体步骤: (0)设置环境变量 设置环境变量使得我们可以直接使用petalin...

plotup的博客 2083

2018西南交通大学ACM新秀杯决赛题解与总结

Problems A Key B 吕元数猜想 C 人类的本质 D A%B problem E 黑珍珠号的诅咒(The Curse of the Black Pearl) F 聚魂棺(Dead man’s Chest) G 喵星网络赛 H N桥问题 I Array                     Problem A. Key Time limit: 1000 ms Memory limit:...

qq_42663062的博客 1936

[知识图谱构建] 一.Neo4j图数据库安装初识及药材供应图谱实例

2012年5月,谷歌公司的知识图谱(Knowledge Graph)产品被正式提出,其旨在将人、地点、物等信息作为实体,将实体间的联系作为关系,并将实体和关系以图的形式进行存储。作为语义网的最新产物,知识图谱这种新型的搜索引擎改变了传统的文本搜索结果,而随后国内公司也开发出了相应产品,例如百度公司的“知心”和搜狗公司的“知立方”等。知识图谱本质上属于一种语义网。知识图谱中的每一条数据或事实一般会采用 &amp;lt;实体,属性,属性值&amp;gt; &amp;lt;实体, 关系,

杨秀璋的专栏 1万+

SIMULINK开发项目实例 1000 例专栏之第802例--基于电机驱动系统的场景实例:永磁同步电机(PMSM)在电动汽车中的矢量控制仿真

随着全球对环境保护的关注增加,电动汽车(Electric Vehicle, EV)因其环保特性而受到广泛关注。永磁同步电机(Permanent Magnet Synchronous Motor, PMSM)由于其高效率、高功率密度和良好的动态响应性能,在电动汽车驱动系统中得到了广泛应用。矢量控制(Field-Oriented Control, FOC)是实现PMSM高性能控制的关键技术之一,它能够实现对电机转矩和磁场的独立控制,从而达到类似直流电机的控制效果。本文将详细介绍如何使用来构建一个。

xiaoheshang_123的博客 270

2019 GDUT RC 1 Problem C(题解)

原题 Problem C. Mooyo Mooyo Input file: standard input Output file: standard output Time limit: 1 second Memory limit: 256 megabytes With plenty of free time on their hands (or rather, hooves),...

weixin_30730053的博客 508

将Windbg附加到软件进程上排查异常闪退的问题

使用Windbg和Process Explorer排查因为内存泄漏导致的软件异常闪退问题。

dvlinker的技术专栏 1万+

2017武汉大学校赛 网络预选赛 简单题题解

补题目补了好几天,越发觉得自己是个菜鸡。。所以写个简单题的题解吧。。反正难的题目也不会做 除了A题题目贴过来都有格式问题。。所以不贴题目了最后会放题目链接 A. One car comes and one car goes Two cars from the East Station and the west Station started to drive toward each

fanesemyk的博客 1191

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

2017WHU校赛color

树型DP

矮矮的夏祭的专栏 482

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

2017武汉大学校赛网络预选赛g题

Input file: standard input Output file: standard output Time limit: 1 second Memory limit: 512 mebibytes Everyone hates the verdict “Time Limit Exceeded” or “TLE”. However, sometimes, we can’t com

creatorx的博客 556

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

2017武汉大学校赛网络预选赛e题

Input file: standard input Output file: standard output Time limit: 1 second Memory limit: 512 mebibytes As one of the most beautiful campus in China, Wuhan University is around several hills, so

creatorx的博客 679

武汉大学校赛(个人总结+补题)

【题意】: B.Color Input file: standard input Output file: standard output Time limit: 1 second Memory limit: 512 mebibytes When Asuho was just a little girl, she has been loving stars, as there are

Crazy 2204

备战ACM校赛

今晚回顾了大一下学期计算智能的两道题,收获了一些东西。先将两道题目po上来。/*6581 Number Triangle    时间限制:500MS  内存限制:1000KDescription        7      3   8    8   1   0  2   7   4   44   5   2   6   5   (Figure 1)Figure 1 shows a number t...

cxm9194634的博客 435

10361 - Automatic Poetry

Problem I Automatic Poetry Input: standard input Output: standard output Time Limit: 2 seconds Memory Limit: 32 MB   “Oh God”, Lara Croft exclaims, “it’s one of these dumb riddles again!”

菜鸟的逆袭 1092

2017武汉大学华中地区程序设计邀请赛个人感悟

第一次打现场赛,而且还出省,果然如那句话所说,不去和优秀的人接触,你永远不知道自己和别人的差距,身处二本弱校,真正地认识到了和别人的差距,别人的气球一个个的升起,而自己从始至终也只是那一个,大一上学期,浪费了很多时间,追求安逸的生活获得的只是精神的空虚; 群里说去年这场比赛的倒数第一这次rank12,武大的面包很好吃,下年我还会来的,立flag;   PS:今年学校没让去55555555,难...

gyr 1664

中原工学院第十一届ACM校赛总结

Problem A. 玄武国 Input file : standard input Output file: standard output Time limit: 1 second Memory limit: 256 megabytes 小 E 只身来到玄武国,准备在一排只有 n 个客栈的地方住宿,这个街道有 m 名刺客组织的刺客,每个刺客的监测半径范围是 k。也就是说,对于处于在 f 号客栈的刺客,他可以监测到[f-k,f+k]所有的客栈。 小 E 不想过多的与刺客组织接触,他已经知道了每个刺客所在的

weixin_53109474的博客 791

2017华中区邀请赛暨武汉大学校赛网络赛小结 + WOJ 642 Lost in WHU

截止目前最失败的一次比赛,奇耻大辱啊,orz……         卡在一些比较难写的题目里面,思路不清晰就在瞎敲代码,越改越死……         我们完全丢了一队的脸,甚至连二队三队都不如了,差点还进不了决赛,失眠难受了一整天……         事后还是那样,抛开这一切,许多问题变得明了起来,对于一些题目赛场上有猜测,后来发现也是对的,但因为陷入一道题而没去完善……         什

alpc_qleonardo 1032

telegraf配置

Telegraf配置文件(telegraf.conf)列出了所有可用的Telegraf插件。在此处查看当前版本:telegraf.conf。 生成配置文件 Telegraf可以自动生成默认的Telegraf配置文件: telegraf config > telegraf.conf 要生成具有特定输入和输出的配置文件,可以使用 --input-filter和–output-filter标志: ...

weixin_40367126的博客 1万+

woj-Soul Artist

Input file: standard input Output file: standard output Time limit: 1 second Memory limit: 512 mebibytes Last year, there were three soul artist in the team Abysswatcher. They were all addicted to

w571523631的博客 461
上一篇: 扩展欧几里得
下一篇: 2017武汉大学校赛网络预选赛e题
creatorx
博客等级 码龄10年 127粉丝 145原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值