static int kSumHelper(int[]A, int k, int i, int t, Map<String,Integer>dp) {
        int n=A.length;
        if (i==n)return 0;
        String key=t+","+k+","+i;
        int val=0;
        if (dp.containsKey(key))
        	return dp.get(key);
        if (k==1) {
            for (int j=i;j<n;++j) {
                if (A[j]==t)
                    ++val;
            }
            dp.put(key,val);
            return val;
        } else if (k==2) {
            for (int l=i, r=n-1;l<r;) {
                int sum=A[l]+A[r];
                int nl=l+1, nr=r-1;
                while (nl<r&&A[nl]==A[l])
                    ++nl;
                while (nr>l&&A[nr]==A[r])
                    --nr;
                if (sum==t) {
                	if (nl==r)
                		val+=(r+1-l)*(r-l)/2;
                	else 
                		val+=(nl-l)*(r-nr);
                    l=nl;
                    r=nr;
                } else if (sum<t)
                    l=nl;
                else 
                    r=nr;
            }
            dp.put(key, val);
            return val;
        }
        val+=kSumHelper(A, k-1,i+1,t-A[i],dp);
        val+=kSumHelper(A, k,i+1,t,dp);
        dp.put(key, val);
        return val;
    }