CodeChef January Long Challenge 2016 - SEAKAM

15 篇文章 0 订阅
  • 又是这种类型的DP,看似需要 n! 的复杂度,其实定义好dp状态就行啦!
题意:

给定一个包含 N 个点的无向图,给定 k 条边,表示无向图中这些边不存在,其余不包括在这 k 条边中的边都存在,求走完整个图(每个点只能访问一次)有多少种走法?
范围:
1N1050k7

思路:

转化一下,问题就是求有多少种 1 n 排列使得排列中不会出现那 k 对数在排列中相邻。

因为 k 比较小,而且这些特殊点最多也只有 14 个,所以我们可以去数位 dp 枚举这14个点的排列状态,然后去加入剩余没有用过的特殊点,如果相邻的两个特殊点属于上面 k 对中的一对的话,那么就这两个点之间必须至少加入一个点,考虑 dp 状态 dp[i][j][k] 表示 i 状态下,最后一个被排列的点为 j ,用掉了 k <script type="math/tex" id="MathJax-Element-17">k</script> 个非特殊点的排列方式!

转移就很简单了啊!略。。。。

代码:
let k = faulty_nodes.size()
let ans = 0 //counter variable
let normal_nodes = N - k;

for mask = 1 to (2^k-1)
{
    for first_node = 0 to k-1
    {
        for number_tied = 0 to k-1
        {
            //appending a new node to the beginning of the arrangement that
            //is given by mask.
            for new_first = 0 to k-1
            {
                if(new_first bit in mask == 0)
                {
                    new_mask = bitwise_or(mask, 2^new_first)
                    missing_edge = 1 if edge (new_first, first_node) missing else 0

                    //adding to the count of sequences starting with new_first and
                    //containing faulty nodes as the ones in the new_mask
                    dp[new_mask][new_first][number_tied + missing_edge] += dp[mask][first_node][number_tied];

                    //note that if the edge (new_first, first_node) is missing,
                    //we will have to tie an element to first_node, i.e.,
                    //increasing number_tied by 1.
                }
            }

            if(mask == (2^k - 1))
            {
                //if all the faulty nodes have been arranged then we can
                //count the number of valid permutations for this
                //particular arrangement

                total_objects = N - number_tied;
                val = dp[mask][first_node][number_tied];

                //getting all ways of arranging items
                get_ways = (total_objects choose k) * (val);

                //multiplying the number of ways of permuting normal nodes.
                get_ways = (get_ways * factorial[normal_nodes]);

                //adding to the counter variable
                ans = (ans + get_ways);
            }
        }
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
order_date sales_region_code item_code first_cate_code second_cate_code sales_chan_name item_price ord_qty 2016-03-15 101 20001 302 408 offline 700 102 2016-03-21 101 20001 302 408 offline 705 19 2016-03-23 101 20001 302 408 offline 702 36 2016-03-24 101 20001 302 408 offline 692 204 2016-03-25 101 20001 302 408 offline 693 36 2016-05-06 101 20001 302 408 offline 707 305 2016-05-09 101 20001 302 408 offline 709 206 2017-08-04 101 20002 303 406 offline 1958 4 2018-03-14 101 20002 303 406 offline 2166 2 2018-03-16 101 20002 303 406 offline 2466 3 2018-03-25 101 20002 303 406 offline 2453 3 2018-03-31 101 20002 303 406 offline 2462 9 以上数据是excel表格,你能看出来吗 上表表格保存在test.xlsx文件:order_date(订单日期,注:订单日期从2015 年 9 月 1日至 2018 年 12 月 20 日)、sales_region_code(销售区域编码)、item_code(产品编码)、first_cate_code (产品大类编码)、second_cate_code (产品细类编码)、sales_chan_name (销售渠道名称)、item_price (产品价格)和 ord_qty (订单需求量) 希望给出下列描述的python代码。 读入表格,将数据转为模型可用的格式。 训练集与测试集的数据要转换成模型可使用的数据格式,数据维度要与模型的输入相匹配。 使用tensorflow创建lstm模型,其训练数据为相同的产品编码,对应的订单日期,对应的订单需求量。然后进行模型训练 模型训练完成后,对不同的产品编码预测其在2019年1月至3月每月的订单需求量。 需要将信息保存在result.xlsx表格中,其中应包含以下数据,产品编码,和对应的2019年1月订单需求量,2019年2月的需求量,2019年3月的需求量。
04-23

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值