This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int solve(int p, int num){ | |
if(p==n) printf("%d\n", num); | |
if(dp[p][num]!=-1) return dp[p][num]; //this line must go first! | |
//if(p==n && num==0) return dp[n][0] = 0; //ignore empty case, but this over write the correct value | |
if(p==n) return dp[p][num%8] = (num%8==0); | |
int t = (num*10)+(s[p]-'0'); | |
//take digit at position p or not | |
return dp[p][num%8] = max(solve(p+1, t%8), solve(p+1, num)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cmath> | |
#include <cstring> | |
#include <ctime> | |
#include <iostream> | |
#include <algorithm> | |
#include <set> | |
#include <vector> | |
#include <sstream> | |
#include <typeinfo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dfs(1,0); | |
dfs(x+1,tot+a[x]); | |
dfs(x+1,tot); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int getMinimum(String[] board, int K) | |
{ | |
int w = board.length; | |
int h = board[0].length(); | |
final int INF = 1000000000; //A large number | |
int res = INF; | |
// For each subrectangle of the board: | |
for (int x0 = 0; x0 < w; x0 ++) { | |
for (int x1 = x0+1; x1 <= w; x1++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef vector<bitset<30> > Grid; | |
template <> | |
struct hash<Grid> | |
{ | |
std::size_t operator()(const Grid& k) const | |
{ | |
size_t ret; | |
for(int i=0;i<k.size();++i) | |
for(int j=0;j<k[0].size();++j) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int ans=55; | |
for(int tryc=0;tryc<N;++tryc){ | |
for(int cntr: vc){ // here I try to squeeze other ducks toward this center duck | |
int t=0; //tmp ans | |
printf("Try col @ %d, center @ %d\n", tryc, cntr); | |
for(int row: vc){ | |
int up=cntr-1, down=cntr+1; | |
for(int c=0;c<N;++c) if(grid[row][c]=='o'){ | |
t += abs(c - tryc); | |
//step toward center: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cmath> | |
#include <cstring> | |
#include <ctime> | |
#include <iostream> | |
#include <algorithm> | |
#include <set> | |
#include <vector> | |
#include <sstream> | |
#include <typeinfo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ctime> | |
#include <iostream> | |
#include <algorithm> | |
#include <set> | |
#include <vector> | |
#include <sstream> | |
#include <typeinfo> | |
#include <fstream> | |
#include <utility> | |
#include <cstring> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#include <string> | |
#include <cstring> | |
#include <sstream> | |
#include <queue> | |
using namespace std; | |
typedef pair<int, int> pii; | |
int N, TC=1; | |
const int U=1000005; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Similars: | |
def maxsim(self, a, b): | |
return max(map(lambda (i,j):len(set(sorted(str(i))) & set(sorted(str(j)))), [(x,y) for x in range(a,b+1) for y in range(a,b+1) if y>x])) |