Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("Ofast")//Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
using namespace std;
struct PairHash {inline std::size_t operator()(const std::pair<int, int> &v) const { return v.first * 31 + v.second; }};
// speed
#define Code ios_base::sync_with_stdio(false);
#define By ios::sync_with_stdio(0);
#define Sumfi cout.tie(NULL);
// alias
using ll = long long;
using ld = long double;
using ull = unsigned long long;
// constants
const ld PI = 3.14159265358979323846; /* pi */
const ll INF = 1e18;
const ld EPS = 1e-9;
const ll MAX_N = 202020;
const ll mod = 1000000007;
// typedef
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef array<ll,3> all3;
typedef array<ll,5> all5;
typedef vector<all3> vall3;
typedef vector<all5> vall5;
typedef vector<ld> vld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef deque<ll> dqll;
typedef deque<pll> dqpll;
typedef pair<string, string> pss;
typedef vector<pss> vpss;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef unordered_set<ll> usll;
typedef unordered_set<pll, PairHash> uspll;
typedef unordered_map<ll, ll> umll;
typedef unordered_map<pll, ll, PairHash> umpll;
// macros
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,m,n) for(ll i=n;i>=m;i--)
#define all(a) begin(a), end(a)
#define rall(a) rbegin(a), rend(a)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define INF(a) memset(a,0x3f3f3f3f3f3f3f3fLL,sizeof(a))
#define ASCEND(a) iota(all(a),0)
#define sz(x) ll((x).size())
#define BIT(a,i) (a & (1ll<<i))
#define BITSHIFT(a,i,n) (((a<<i) & ((1ll<<n) - 1)) | (a>>(n-i)))
#define pyes cout<<"YES\n";
#define pno cout<<"NO\n";
#define endl "\n"
#define pneg1 cout<<"-1\n";
#define ppossible cout<<"Possible\n";
#define pimpossible cout<<"Impossible\n";
#define TC(x) cout<<"Case #"<<x<<": ";
#define X first
#define Y second
// utility functions
template <typename T>
void print(T &&t) { cout << t << "\n"; }
template<typename T>
void printv(vector<T>v){ll n=v.size();rep(i,0,n){cout<<v[i];if(i+1!=n)cout<<' ';}cout<<endl;}
template<typename T>
void printvln(vector<T>v){ll n=v.size();rep(i,0,n)cout<<v[i]<<endl;}
void fileIO(string in = "input.txt", string out = "output.txt") {freopen(in.c_str(),"r",stdin); freopen(out.c_str(),"w",stdout);}
void readf() {freopen("", "rt", stdin);}
template<typename T>
void readv(vector<T>& v){rep(i,0,sz(v)) cin>>v[i];}
template<typename T, typename U>
void readp(pair<T,U>& A) {cin>>A.first>>A.second;}
template<typename T, typename U>
void readvp(vector<pair<T,U>>& A) {rep(i,0,sz(A)) readp(A[i]); }
void readvall3(vall3& A) {rep(i,0,sz(A)) cin>>A[i][0]>>A[i][1]>>A[i][2];}
void readvall5(vall5& A) {rep(i,0,sz(A)) cin>>A[i][0]>>A[i][1]>>A[i][2]>>A[i][3]>>A[i][4];}
void readvvll(vvll& A) {rep(i,0,sz(A)) readv(A[i]);}
struct Combination {
vll fac, inv;
ll n, MOD;
ll modpow(ll n, ll x, ll MOD = mod) { if(!x) return 1; ll res = modpow(n,x>>1,MOD); res = (res * res) % MOD; if(x&1) res = (res * n) % MOD; return res; }
Combination(ll _n, ll MOD = mod): n(_n + 1), MOD(MOD) {
inv = fac = vll(n,1);
rep(i,1,n) fac[i] = fac[i-1] * i % MOD;
inv[n - 1] = modpow(fac[n - 1], MOD - 2, MOD);
rrep(i,1,n - 2) inv[i] = inv[i + 1] * (i + 1) % MOD;
}
ll fact(ll n) {return fac[n];}
ll nCr(ll n, ll r) {
if(n < r or n < 0 or r < 0) return 0;
return fac[n] * inv[r] % MOD * inv[n-r] % MOD;
}
};
struct Matrix {
ll r,c;
vvll matrix;
Matrix(ll r, ll c, ll v = 0): r(r), c(c), matrix(vvll(r,vll(c,v))) {}
Matrix operator*(const Matrix& B) const {
Matrix res(r, B.c);
rep(i,0,r) rep(j,0,B.c) rep(k,0,B.r) {
res.matrix[i][j] = (res.matrix[i][j] + matrix[i][k] * B.matrix[k][j] % mod) % mod;
}
return res;
}
Matrix copy() {
Matrix copy(r,c);
copy.matrix = matrix;
return copy;
}
Matrix pow(ll n) {
assert(r == c);
Matrix res(r,r);
Matrix now = copy();
rep(i,0,r) res.matrix[i][i] = 1;
while(n) {
if(n & 1) res = res * now;
now = now * now;
n /= 2;
}
return res;
}
};
// geometry data structures
template <typename T>
struct Point {
T y,x;
Point(T y, T x) : y(y), x(x) {}
Point(pair<T,T> p) : y(p.first), x(p.second) {}
Point() {}
void input() {cin>>y>>x;}
friend ostream& operator<<(ostream& os, const Point<T>& p) { os<<p.y<<' '<<p.x<<'\n'; return os;}
Point<T> operator+(Point<T>& p) {return Point<T>(y + p.y, x + p.x);}
Point<T> operator-(Point<T>& p) {return Point<T>(y - p.y, x - p.x);}
Point<T> operator*(ll n) {return Point<T>(y*n,x*n); }
Point<T> operator/(ll n) {return Point<T>(y/n,x/n); }
Point<T> rotate(Point<T> center, ld angle) {
ld si = sin(angle * PI / 180.), co = cos(angle * PI / 180.);
ld y = this->y - center.y;
ld x = this->x - center.x;
return Point<T>(y * co - x * si + center.y, y * si + x * co + center.x);
}
ld distance(Point<T> other) {
T dy = abs(this->y - other.y);
T dx = abs(this->x - other.x);
return sqrt(dy * dy + dx * dx);
}
};
template<typename T>
struct Line {
Point<T> A, B;
Line(Point<T> A, Point<T> B) : A(A), B(B) {}
Line() {}
void input() {
A = Point<T>();
B = Point<T>();
A.input();
B.input();
}
T ccw(Point<T> &a, Point<T> &b, Point<T> &c) {
T res = a.x * b.y + b.x * c.y + c.x * a.y;
res -= (a.x * c.y + b.x * a.y + c.x * b.y);
return res;
}
bool isIntersect(Line<T> o) {
T p1p2 = ccw(A,B,o.A) * ccw(A,B,o.B);
T p3p4 = ccw(o.A,o.B,A) * ccw(o.A,o.B,B);
if (p1p2 == 0 && p3p4 == 0) {
pair<T,T> p1(A.y, A.x), p2(B.y,B.x), p3(o.A.y, o.A.x), p4(o.B.y, o.B.x);
if (p1 > p2) swap(p2, p1);
if (p3 > p4) swap(p3, p4);
return p3 <= p2 && p1 <= p4;
}
return p1p2 <= 0 && p3p4 <= 0;
}
pair<bool,Point<ld>> intersection(Line<T> o) {
if(!this->intersection(o)) return {false, {}};
ld det = 1. * (o.B.y-o.A.y)*(B.x-A.x) - 1.*(o.B.x-o.A.x)*(B.y-A.y);
ld t = ((o.B.x-o.A.x)*(A.y-o.A.y) - (o.B.y-o.A.y)*(A.x-o.A.x)) / det;
return {true, {A.y + 1. * t * (B.y - A.y), B.x + 1. * t * (B.x - A.x)}};
}
//@formula for : y = ax + b
//@return {a,b};
pair<ld, ld> formula() {
T y1 = A.y, y2 = B.y;
T x1 = A.x, x2 = B.x;
if(y1 == y2) return {1e9, 0};
if(x1 == x2) return {0, 1e9};
ld a = 1. * (y2 - y1) / (x2 - x1);
ld b = -x1 * a + y1;
return {a, b};
}
};
template<typename T>
struct Circle {
Point<T> center;
T radius;
Circle(T y, T x, T radius) : center(Point<T>(y,x)), radius(radius) {}
Circle(Point<T> center, T radius) : center(center), radius(radius) {}
Circle() {}
void input() {
center = Point<T>();
center.input();
cin>>radius;
}
bool circumference(Point<T> p) {
return (center.x - p.x) * (center.x - p.x) + (center.y - p.y) * (center.y - p.y) == radius * radius;
}
bool intersect(Circle<T> c) {
T d = (center.x - c.center.x) * (center.x - c.center.x) + (center.y - c.center.y) * (center.y - c.center.y);
return (radius - c.radius) * (radius - c.radius) <= d and d <= (radius + c.radius) * (radius + c.radius);
}
bool include(Circle<T> c) {
T d = (center.x - c.center.x) * (center.x - c.center.x) + (center.y - c.center.y) * (center.y - c.center.y);
return d <= radius * radius;
}
};
ll __gcd(ll x, ll y) { return !y ? x : __gcd(y, x % y); }
all3 __exgcd(ll x, ll y) { if(!y) return {x,1,0}; auto [g,x1,y1] = __exgcd(y, x % y); return {g, y1, x1 - (x/y) * y1}; }
ll __lcm(ll x, ll y) { return x / __gcd(x,y) * y; }
ll modpow(ll n, ll x, ll MOD = mod) { n%=MOD; if(!x) return 1; ll res = modpow(n,x>>1,MOD); res = (res * res) % MOD; if(x&1) res = (res * n) % MOD; return res; }
umll dp[55][55];
void helper(ll a, ll e) {
if(a == 0) dp[a][e] = {{0,1}};
if(sz(dp[a][e])) return;
ll n = a + e, l = n / 2, r = n - l;
umll& now = dp[a][e];
rep(i,0,min(a,l) + 1) {
ll A = i, E = l - i;
if(E > e) continue;
helper(A,E);
helper(a-A,e-E);
for(auto& [k1,v1] : dp[A][E]) {
for(auto& [k2,v2] : dp[a-A][e-E]) {
ll score = max(k1,k2) + a;
if(score > 1000) continue;
now[score] = (now[score] + v1 * v2 % mod) % mod;
}
}
}
}
ll solve(ll a, ll e, ll v) {
dp[0][0] = {{0,1}};
dp[1][0] = {{1,1}};
helper(a,e);
if(!dp[a][e].count(v)) return 0;
return dp[a][e][v];
}
int main() {
Code By Sumfi
cout.precision(12);
ll tc = 1;
cin>>tc;
rep(i,1,tc+1) {
ll a,e,v;
cin>>a>>e>>v;
print(solve(a,e,v));
}
return 0;
}
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int DP[60][60][200];
const long long MOD = 1000000007;
long long funct(int a, int e, int v){if (v < 0){return 0;} if (DP[a][e][v] != -1){return DP[a][e][v];}
if (a+e <= 1){return DP[a][e][v] = (a<=v);}
long long sol = 0LL; int t = (a+e)/2; for (int i = 0; i < t+1; i++)
{if ((i <= a) && (t-i <= e)){sol += funct(i,t-i,v-a)*funct(a-i,e-(t-i),v-a); sol%=MOD;}}
return DP[a][e][v] = sol;}
int main(){int t; memset(DP,-1,sizeof(DP)); scanf("%d",&t);
while (t--){int A, E, V; scanf ("%d%d%d", &A, &E, &V); long long temp = 0;
temp = (funct(A,E,V)-funct(A,E,V-1)+MOD)%MOD; printf("%lld\n",temp);}}
#include<stdio.h>
#include<string.h>
#define ll long long
#define M 1000000007
ll dp[60][60][160];
ll S(int a,int e,int v){
int m=(a+e)/2,i;
ll p=0;
if(v<0||~dp[a][e][v]||a+e<=1)
return(v<0)?0:((~dp[a][e][v])?dp[a][e][v]:(dp[a][e][v]=(a<=v)));
for(i=-1;++i<=m;p=(i<=a&&m-i<=e)?(p+S(i,m-i,v-a)*S(a-i,e-(m-i),v-a))%M:p);
return dp[a][e][v]=p;
}
main()
{
int f,a,e,v;
ll r;
for(scanf("%d",&f) && memset(dp,-1,sizeof dp);
f--;
scanf("%d%d%d",&a,&e,&v),printf("%lld\n",(r=v>152?0:(r=(S(a,e,v)-S(a,e,v-1))%M)<0?r+M:r)));
return 0;
}
import java.io.DataInputStream;
import java.io.InputStream;
public class Main{
static long hashedcounts[][][];
static int vlist[][][];
static int vlistindex[][];
static int mod=1000000007;
static int reqs[][];
public static void main(String args[]) throws Exception
{
ParserCount p=new ParserCount(System.in);
hashedcounts=new long[101][51][1001];
vlist=new int[101][51][1001];
vlistindex=new int[101][51];
int T=p.nextInt();
reqs=new int[101][51];
int inputs[][]=new int[T][3];
StringBuffer sb=new StringBuffer();
for(int i=0;i<T;i++)
{
int A=p.nextInt();int E=p.nextInt();int V=p.nextInt();
inputs[i][0]=A;inputs[i][1]=E;inputs[i][2]=V;
if((A+E)>50)
{
reqs[A+E][A]=1;
}
}
preProcess();
populate();
int A,E,V;
for(int i=0;i<T;i++)
{
A=inputs[i][0];E=inputs[i][1];V=inputs[i][2];
int l=A+E;
//System.out.println(hashedcounts[l][A][V]);
sb.append(hashedcounts[l][A][V]+"\n");
}
System.out.print(sb.toString());
}
public static void populate()
{
for(int length=3;length<=100;length++)
{
//System.out.println("Starting L="+length+"...");
int leftl,rightl;
if(length%2==1)
{
leftl=length/2;
rightl=leftl+1;
}
else
{
leftl=length/2;
rightl=length/2;
}
for(int A=0;A<=length && A<=50;A++)
{
if(length>50)
{
if(reqs[length][A]==0)//these are not necessary
continue;
}
//System.out.println("\t A="+A);
int ways=A;//at root it has this many A's
for(int leftA=0;leftA<=A;leftA++)
{
int rightA=A-leftA;
// if(leftA>leftl || rightA>rightl)
// continue;
int lcount=vlistindex[leftl][leftA];
int rcount=vlistindex[rightl][rightA];
//cross product start
for(int m=0;m<lcount;m++)
{
for(int n=0;n<rcount;n++)
{
int val1=vlist[leftl][leftA][m];
int val2=vlist[rightl][rightA][n];
if(ways+val1>1000 || ways+val2>1000)//to be verified
continue;
if(val1>val2)
{
if(hashedcounts[length][A][ways+val1]==0)//new value added. hence add it to vlist
{
//System.out.println(vlistindex[length][A]);
vlist[length][A][vlistindex[length][A]]=ways+val1;
vlistindex[length][A]++;
}
hashedcounts[length][A][ways+val1]+=((hashedcounts[leftl][leftA][val1]*hashedcounts[rightl][rightA][val2])%mod);
hashedcounts[length][A][ways+val1]=hashedcounts[length][A][ways+val1]%mod;
}
else
{
if(hashedcounts[length][A][ways+val2]==0)//new value added. hence add it to vlist
{
vlist[length][A][vlistindex[length][A]]=ways+val2;
vlistindex[length][A]++;
}
hashedcounts[length][A][ways+val2]+=((hashedcounts[leftl][leftA][val1]*hashedcounts[rightl][rightA][val2])%mod);
hashedcounts[length][A][ways+val2]=hashedcounts[length][A][ways+val2]%mod;
}
}
}
}
//print stuff
// for(int k=0;k<vlistindex[length][A];k++)
// {
// System.out.print("("+vlist[length][A][k]+" "+hashedcounts[length][A][vlist[length][A][k]]+")");
// }
//System.out.println("\n");
}
}
}
public static void preProcess()
{
hashedcounts[0][0][0]=1;vlist[0][0][vlistindex[0][0]++]=0;
hashedcounts[1][0][0]=1;vlist[1][0][vlistindex[1][0]++]=0;
hashedcounts[1][1][1]=1;vlist[1][1][vlistindex[1][1]++]=1;
hashedcounts[2][0][0]=1;vlist[2][0][vlistindex[2][0]++]=0;
hashedcounts[2][1][2]=2;vlist[2][1][vlistindex[2][1]++]=2;
hashedcounts[2][2][3]=1;vlist[2][2][vlistindex[2][2]++]=3;
}
}
class ParserCount
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public ParserCount(InputStream in)
{
din = new DataInputStream(in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String nextString() throws Exception
{
StringBuffer sb=new StringBuffer("");
byte c = read();
while (c <= ' ') c = read();
do
{
sb.append((char)c);
c=read();
}while(c!='\r');
return sb.toString();
}
public int nextInt() throws Exception
{
int ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = c == '-';
if (neg) c = read();
do
{
ret = ret * 10 + c - '0';
c = read();
} while (c > ' ');
if (neg) return -ret;
return ret;
}
private void fillBuffer() throws Exception
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1) buffer[0] = -1;
}
private byte read() throws Exception
{
if (bufferPointer == bytesRead) fillBuffer();
return buffer[bufferPointer++];
}
}
import sys
import math
M = 1000000007
rs = {}
def fn(An, En, V):
global rs, M
try:
return rs[An][En][V]
except:
## if V < 0:
## return 0
if rs.has_key(An):
if not rs[An].has_key(En):
rs[An][En] = {}
else:
rs[An] = {}
rs[An][En] = {}
rs[An][En][V] = None
if V < An:
rs[An][En][V] = 0
else :
if An == 0:
rs[An][En][V] = 1
else:
if An == 1 and En == 0:
if V == 0:
rs[An][En][V] = 0
else:
rs[An][En][V] = 1
if rs[An][En][V] == None:
vRemain = V - An
s = (An + En) / 2
cnt = 0
for an1 in range(max(0, s - En), min(An, s)+1):
cnt += fn(an1, s - an1, vRemain) * fn(An - an1, En - s + an1, vRemain)
rs[An][En][V] = cnt % M
return rs[An][En][V]
def main():
testCases = int(sys.stdin.readline())
cases = []
for n in range(0, testCases):
An, En, V = sys.stdin.readline().split(' ')
print "%s" % ((fn(int(An), int(En), int(V)) - fn(int(An), int(En), int(V)-1) + M ) % M)
if __name__ == '__main__':
main()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ProgrammingContest.CodeChef.Contest.July_2011_Long_Contest
{
class A_E_Hash_Function
{
const long mod = 1000000007;
static Dictionary<int, long>[,] memo = new Dictionary<int, long>[51, 51];
static Dictionary<int,long> rec(int A, int E)
{
if (memo[A, E] != null)
return memo[A,E];
memo[A, E] = new Dictionary<int, long>();
Dictionary<int, long> res = memo[A, E];
if (A + E <= 1 || A == 0)
{
res[A] = 1;
return res;
}
int n = (A + E) / 2;
for (int i = 0; i <= n; i++)
{
if (A < i || E < n - i)
continue;
var d1 = rec(i, n - i);
var d2 = rec(A - i, E - (n - i));
foreach (var v in d1)
foreach (var u in d2)
{
int max = Math.Max(v.Key, u.Key),
val = A + max;
if (!res.ContainsKey(val))
res[val] = 0;
res[val] = (res[val] + u.Value * v.Value) % mod;
}
}
return res;
}
static void Main()
{
int T = int.Parse(Console.ReadLine());
while(T-- > 0)
{
var xs = Array.ConvertAll(Console.ReadLine().Split(' '), sss => int.Parse(sss));
int A = xs[0],
E = xs[1],
V = xs[2];
var dic = rec(A, E);
Console.WriteLine(dic.ContainsKey(V) ? dic[V] : 0);
}
}
}
}
package main
import (
"fmt"
)
const (
M = int32(1000000007)
M64 = int64(1000000007)
aMax = 50
eMax = 50
vMax = 1000
)
var rs [aMax + 1][eMax +1][vMax +1]int32
func fn(an, en, v int) int32{
if v < 0{
return 0
}
if rs[an][en][v] == -1{
if v < an {
rs[an][en][v] = 0
} else if an == 0{
rs[an][en][v] = 1
} else if an == 1 && en == 0{
if v == 0{
rs[an][en][v] = 0
} else {
rs[an][en][v] = 1
}
}
if rs[an][en][v] == -1{
r := v - an
s := (an + en) / 2
var cnt int64
start := s - en
if en > s{
start = 0
}
end := s
if an < s{
end = an
}
for a1 := start; a1 <= end ;a1++{
cnt = (cnt + (int64(fn(a1, s -a1, r)) * int64(fn(an-a1, en-s+a1, r))) ) % M64
}
rs[an][en][v] = int32(cnt)
}
}
return rs[an][en][v]
}
func main() {
var tn int
var out int32
for i :=0; i <= aMax; i++{
for j :=0; j <= eMax; j++{
for k :=0; k <= vMax; k++{
rs[i][j][k] = -1
}
}
}
fmt.Scanln(&tn)
for i :=0; i < tn; i++{
var a, e, v int
fmt.Scanln(&a, &e, &v)
out = (fn(a, e, v) - fn(a, e, v -1 ) + M) % M
fmt.Printf("%d\n", out)
}
}
In our experience, we suggest you solve this A-E Hash Function CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the A-E Hash Function CodeChef Solution.
I hope this A-E Hash Function CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.
Keep Learning!