![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
代码库
Orion233
这个作者很懒,什么都没留下…
展开
-
RMQ+ST 区间最值/区间最多频次
区间最值:#include <cstdio> #include <cstring> #include <cmath> #include <iostream> using namespace std; const int MAXN = 100117; int n,query; int num[MAXN];int F_Min[MAXN][20],F_Max[MAXN][20];void Init() {原创 2017-05-04 21:37:11 · 620 阅读 · 0 评论 -
多重背包模板
#include<iostream> #include<cstring> #include<cstdio> #define MAXV 100001 #define MAXN 101 #define INF -100000000using namespace std;int d[MAXV],weight[MAXN],cnt[MAXN],V;void OneZeroPack(int c,int w) {原创 2017-08-06 11:04:12 · 183 阅读 · 0 评论 -
#HDU 1159 Common Subsequence
Common Subsequence题意&分析: 对于给定的两个字符串,求最长公共子序列。直接用LCS算法,一个DP。代码如下:#include <bits/stdc++.h> #define INF 0x3f3f3f3f #define TEST cout<<"stop here"<<endl using namespace std; typedef long long ll; const ll原创 2017-08-06 16:23:40 · 191 阅读 · 0 评论 -
HDU 1565 方格取数(1)
数组不可以直接开,剪枝之后求算一下所有满足题目条件的状态数目,然后再开数组,30000足够。代码如下:#pragma comment(linker, "/STACK:1024000000,1024000000") #include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #原创 2017-09-24 19:38:51 · 160 阅读 · 0 评论 -
位运算 反转卡片问题
#pragma comment(linker, "/STACK:1024000000,1024000000") #include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map原创 2017-09-12 19:41:00 · 246 阅读 · 0 评论 -
【强连通分量】Tarjan(缩点)POJ1236-Network of Schools
题意: N个点的有向图G,若有路从u通向v,则称u可达v(v不一定可达u)。现给出各点之间的连接关系。 Q1:求出至少从几个点出发,才能使得所有的点均可以遍历一遍; Q2:至少需要添加几条单向边,才能使得从这些点中任何一个出发都可以遍历全部点(使G强连通)。分析:和最近学的离散数学有关。这个题目可以用tarjan求图G强连通分量(缩点)。如果只有一个强连通分量则图G强连通,任意两点可达,如果有原创 2017-10-27 21:34:16 · 261 阅读 · 0 评论 -
[模板] 网络流
最大流 Dinic 算法struct edge { int to, cap, rev; }; vector<edge> G[N]; int level[N]; int iter[N]; void add_edge(int from, int to, int cap) { G[from].push_back((edge){to, cap, G[to].size()}); G[t原创 2017-09-25 22:09:46 · 187 阅读 · 0 评论 -
#HDU 2444 The Accomodation of Students
二分匹配,先判断是否是二分图,再求最大匹配。模板如下:#pragma comment(linker, "/STACK:1024000000,1024000000") #include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #inclu原创 2017-10-11 16:14:05 · 234 阅读 · 0 评论 -
组合数公式&Lucas大组合数
普通组合数ll C(ll m,ll n) { if(m==0||n==m) return 1; ll sb=min(m,n-m); ll f=1,f1; for(ll i=1;i<=sb;i++) { f1=f*(n-i+1)/(i); f=f1; } return f1; }Lucas大数组合数const ll原创 2017-08-13 15:15:38 · 375 阅读 · 0 评论 -
大数加法
#include <stdio.h> #include <string.h> #define MAXLEN 1000 char a1[MAXLEN]; char a2[MAXLEN]; static int v1[MAXLEN]; static int v2[MAXLEN]; static int v3[MAXLEN]; int i,j,n,L,z; void main(void) { sc原创 2017-08-13 14:56:05 · 191 阅读 · 0 评论 -
分治法 or BIT 求逆序对
方法1: 求逆序对可以利用归并排序来求,其实就是分治。 归并排序在排序过程很中对于一样的数比较是不会改变次序的,因而可以用来求逆序对。 代码如下: 1 #include<stdio.h> 2 3 void Merge(int ,int ,int ); 4 void mergeSort(int ,int ); 5 6 int ch[20000],temp[20000]; 7 in原创 2017-04-25 20:19:38 · 504 阅读 · 0 评论 -
「模版」RMQ+ST表
RMQ+ Sparse Table(稀疏表)实现模版#include "stdio.h" #include "math.h" #define MAXN 100 #define max(a,b) (a > b ? a : b) const int num[MAXN]; int dp[MAXN][20]; void create_max (int n) { int i,j,t; for原创 2017-04-25 22:35:41 · 192 阅读 · 0 评论 -
树状数组
ll lowbit(ll x){ return x&-x; } void add(ll i,ll x){ while(i<=n){ c[i]+=x; i+=lowbit(i); } } ll query(ll x){ ll ans=0; while(x>0){ ans+=c[x]; x-=lowb原创 2017-04-27 21:27:19 · 153 阅读 · 0 评论 -
区间dp模板
int dp[1010][1010]; int main() { for(int i=0;i原创 2017-08-07 16:22:46 · 179 阅读 · 0 评论 -
#POJ 1651 Multiplication Puzzle
Multiplication Puzzle 题意&分析: 给定一个数列,出去第一个和最后一个数,中间的数都可以取,再左边和右边各取一个数,三者相乘,即m[ i ]* m[ k ] * m [ j ] (1 <= i < k < j <= n ) ; 求最小的和。这道题类似矩阵连乘的问题(传送门)。dp[ i ][ j ] 的含义是在区间[ i - 1, j ] 的区间内最小的乘法和。这里和一般的区原创 2017-08-08 16:18:49 · 178 阅读 · 0 评论 -
日期计算
计算最近的日期星期相同的的年份。#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #inclu原创 2017-08-13 09:33:10 · 250 阅读 · 0 评论 -
尺取法
void worm_solve() { int res=MAX; int s=0,t=0,sum=0; for(;;) { while(t<n && sum < S){ sum+=a[t++]; } if(sum<S) break; res=min(res,t-s); sum-=a[s++]原创 2017-09-10 17:43:46 · 266 阅读 · 0 评论