牛牛打怪
int dp[1000005];
class Solution {
public:
/**
*
* @param n int整型
* @param DEF int整型vector
* @return int整型
*/
int Minimumdays(int n, vector<int>& DEF) {
// write code here
sort(DEF.begin(),DEF.end());
dp[0]=DEF[0];
for(int i=1;i<DEF.size();i++)
{
dp[i]=max(dp[i-1]+1,DEF[i]);
}
return dp[n-1];
}
};
简单的公式
const int mode=1e9+7;
class Solution {
public:
/**
* 返回c[n]%1000000007的值
* @param n long长整型 即题目中的n
* @return int整型
*/
long long Mode(long long a, long long b){
long long sum = 1;
while (b) {
if (b%2) {
sum =(sum*a)%mode;
b--;
}
b/=2;
a=a*a%mode;
}
return sum;
}
int Answerforcn(long long n) {
// write code here
long long an=2*Mode(3,n-1)%mode;
long long bn=7*Mode(5,n-1)%mode;
long long cn=an*bn%mode;
int ans=cn;
return ans;
}
};
class Solution
{
public:
typedef long long ll;
ll n, k, d[100010];
ll ans = 0, cnt = 1;
inline void dfs(ll x, ll p)
{
for (ll i = -k + 2; i <= 1; ++i) {
if (x * k + i <= n) {
++cnt;
ans += (d[p] ^ d[cnt]);
dfs(x * k + i, cnt);
} else return;
}
}
long long tree6(int K, vector<int> &a)
{
n = a.size();
k = K;
for (int i = 0; i < n; ++i)
{
d[i + 1] = a[i];
}
dfs(1, 1);
return ans;
}
};