Java simple sort and count
See comments for explanation\n1, sort the array from min to max;\n\n2. for each different right tail number tail = nums[r], \nwe find the highest left head numb
See comments for explanation\n1, sort the array from min to max;\n\n2. for each different right tail number tail = nums[r], \nwe find the highest left head number head = nums[l]:\nthat head + tail <= target (t for short);  \nThen we can form a valid subsequence: head ... tail; \nany numver between tail and head could be contained or not contained in the subsequence, then wen can get  f(l) = 2^(r - l  - 1) different subsequences.\n\n3, then any number nums[i]  <= head, that is i <= l, all the subsequence start from nums[i], end with nums[r], will be valid subsequence;\nthere will be  f(i) = 2^(r - i  - 1) those subsquence; \nfor each different r, there will be (l + 1) different i, where i = 0, 1, 2,..., l;\nthe total count will be:\n```\nsigma (f(i))  = f(l) * (2 ^ (l + 1) - 1) \nthat is:\nsigma (f(i)) = 2 ^ (r - l - 1) * (2 ^ (l + 1) - 1);\n```\n\nprove of sigma (f(i)) = 2 ^ (r - l - 1) * (2 ^ (l + 1) - 1):\n```\nsigma (f(i)) = f(0) + f(1) + .. + f(l) = 2 ^ (l - 0) * f(l) + 2 ^ (l -1) * f(l)... + f(l)\n= f(l) * (2 ^ (l - 0) + 2 ^ (l -1) + ... + 1) \n=  f(l) * (2 ^ (l + 1) - 1)\nsince f(l) = 2^(r - i  - 1) \nsigma (f(i)) = 2 ^ (r - l - 1) * (2 ^ (l + 1) - 1)\n```\n\n\n\ncode:\n```\n    public int numSubseq(int[] nums, int t) {\n        Arrays.sort(nums);\n        int n = nums.length, l = 0, r = n - 1, mod = (int)1e9 + 7;\n        long res = 0, pow[] = new long[n + 1];\n        pow[0] = 1;\n        for (int i = 1 ; i <= n ; ++i) pow[i] = pow[i - 1] * 2 % mod;\n        while(l <= r && nums[r] + nums[l] > t) r--; // find the first right pointer;\n        while(l <= r){\n            while (l <= r && nums[r] + nums[l] <= t) l++;\n            l--;\n            if (r == l) res = (res + pow[l + 1] - 1) % mod;   // corner casem \n            else res = (res + pow[r - l - 1] * (pow[l + 1] - 1)) % mod;  //sigma(f(l))\n            r--;\n        }\n        return (int) res;\n    }\n```
[]