Old Sorting Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1166 Description Given an array containing a permutation of 1 to n, you have to find the minimum number of swaps to sort the array…
//把一个序列转换成严格递增序列的最小花费 CF E - Sonya and Problem Wihtout a Legend //dp[i][j]:把第i个数转成第j小的数,最小花费 //此题与poj 3666相似 a[i]转换成a[i]-i #include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <vector> #inclu…
这两个题是一样的,不过数据范围不同. 思路1: 在CF713C中,首先考虑使生成序列单调不下降的情况如何求解.因为单调上升的情况可以通过预处理将a[i]减去i转化成单调不下降的情况. 首先,生成的序列中的每个数一定是原序列中的数.于是可以通过dp+离散化技巧解决.dp[i][j]表示把前i个数变成单调不下降的序列,并且a[i]不超过第j大的数所需要的最小代价. 实现1: #include <bits/stdc++.h> using namespace std; typedef long lon…
//把一个序列转换成非严格递增序列的最小花费 POJ 3666 //dp[i][j]:把第i个数转成第j小的数,最小花费 #include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <vector> #include <math.h> // #include <memory.h> using namespace…
题意:一棵树,有很多分叉,每个分叉上最多有1个苹果. 给出n,接下来n-1行,每行u,v,表示分叉u,v之间有树枝相连.这里数据中u相当于树中的父节点,v相当于子节点. 给出两个操作: 1.C x  如果分叉x有一个苹果,表示该苹果被摘下:如果没苹果,表示该分叉长出1个苹果. 2.Q x  查询以分叉x为根节点的子树中所含有的苹果,包括分叉x. 思路:用树的后根遍历将树转化成一个序列,然后用树状数组维护. 树的后根遍历(先遍历每棵子树,再遍历根节点)实质上是按照自下而上.从左至右的顺序将非线性结…
这题应该可以用费用流写吧?不过我想不出贪心来TAT.其实还是单调队列乱搞啊T_T //ÍøÉϵÄ̰ÐÄËã·¨ºÃÉñ°¡¡£¡£¡£ÎÒÖ»»áÓÃ×îС·ÑÓÃ×î´óÁ÷ÅÜTAT #include<cstdio> #include<cstring> #include<cctype> #include<algorithm> #include<queue> using namespace std; #define rep(i,s,t)…
S - Making the Grade POJ - 3666 这个题目要求把一个给定的序列变成递增或者递减序列的最小代价. 这个是一个dp,对于这个dp的定义我觉得不是很好想,如果第一次碰到的话. 上网看了一下题解,dp[i][j]表示前面 i 位已经是有序的了,第 i+1 位变成第j大的最小代价. 这个转移可以保证有序这个条件. 递增递减d两次. 这个题目要离散化,为什么要离散化呢,推荐博客 我以前就是感觉数据大就要离散化,不然数组存不下,不过看了这篇题解感觉他讲的很对啊. #include…
机器学习可以被用于时间序列预测. 在机器学习能使用之前,时间序列预测需要被重新转化成有监督学习.将一个序列组合成成对的输入输出序列. 在这篇教程中,你会发现如何通过使用机器学习算法将单变量和多变量的时间预测序列转化成有监督学习. 在看完这篇教程之后,你会知道: 1.如何写一个将时间序列的数据集转化成有监督学习的数据集的函数. 2.如何将机器学习用于一个单变量的时间序列. 3.如何将机器学习用于一个多变量的时间序列. 开始吧~ 时间序列vs有监督学习 开始之前,我们先来看看时间序列和有监督学习的数…
A Simple Tree Problem Time Limit: 3000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 368664-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Discuss Next Type: None   None Graph Theory 2-…
#include "stdio.h" #include "stdlib.h" #define random(x) (rand()%x) void creat_array(int a[],int len,int max); void print_array(int a[],int n); void main(){ printf("please input two numbers as the array's length and the array's ma…