Skip to content

Instantly share code, notes, and snippets.

View carlosvinicios's full-sized avatar

Carlos Vinícios carlosvinicios

View GitHub Profile
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
char tab[2][N];
int prev[2][N], dp[N][N][2][2];
int main(){
#ifndef ONLINE_JUDGE
@carlosvinicios
carlosvinicios / lcs.cpp
Created January 8, 2016 15:57
Maior subsequência comum
#include <bits/stdc++.h>
using namespace std;
const int NM = 1e3 + 10;
char s[2][NM];
int dp[NM][NM];
int main(){
int n, m;
@carlosvinicios
carlosvinicios / lis.cpp
Created January 8, 2016 13:04
Maior subsequêcia crescente
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int a[N], dp[N];
int main(){
int n;
scanf("%d", &n);
@carlosvinicios
carlosvinicios / mochila.cpp
Created January 8, 2016 11:57
Algoritmo da mochila
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10, L = 110;
int v[N], p[N], dp[N][L];
int main(){
int n, l;
scanf("%d %d", &n, &l);
@carlosvinicios
carlosvinicios / kadane.cpp
Created January 8, 2016 11:37
Algoritmo de Kadane
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
scanf("%d", &n);
int best = INT_MIN, ans = INT_MIN;
for(int i = 1, v; i <= n; i++){
scanf("%d", &v);
best = max(best + v, v);
@carlosvinicios
carlosvinicios / bit.cpp
Created January 7, 2016 23:03
Binary Indexed Tree
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int bit[N];
void add(int pos, int val){
for(int i = pos; i < N; i += (i & -i)){
bit[i] += val;
@carlosvinicios
carlosvinicios / segment-tree-com-lazy.cpp
Created January 7, 2016 21:57
Segment Tree com Lazy Propagation
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int node[4*N], lazy[4*N];
void upd(int seg, int l, int r){
node[seg] += (r - l + 1)*lazy[seg];
if(l != r){
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int node[4*N];
void modify(int seg, int l, int r, int p, int val){
if(l == r){
node[seg] += val;
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
scanf("%d", &n);
int sqn = sqrt(n);
printf("fatores(%d) =", n);
for(int i = 2; i <= sqn && n > 1; i++){
while(n%i == 0){
@carlosvinicios
carlosvinicios / crivo-de-eratostenes.cpp
Created January 7, 2016 20:24
Crivo de Eratóstenes
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
bool notprime[N];
void crivo(int n){
int sqn = sqrt(n);
notprime[1] = true;