#include <stdio.h>
#include <string.h>
![](/Images/OutliningIndicators/None.gif)
int a[101],b[101],c[101];
int f[512][512];
int n,m;
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
void DP()
![](/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](/Images/OutliningIndicators/ContractedBlock.gif) {
int i, j, k;
for(k=0;k<n;k++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for(i=0;i<=m;i++)
for(j=0;j<=m;j++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if(f[i][j]==1)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
int use=0;
while(use<=c[k])
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if(a[k]*use + i > m || b[k]*use + j > m)
break;
if(f[a[k]*use + i][b[k]*use + j]==0)
f[a[k]*use + i][b[k]*use + j]=2;
use++;
}
}
}
for(i=0;i<=m;i++)
for(j=0;j<=m;j++)
if(f[i][j]==2)
f[i][j]=1;
}
}
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
int main()
![](/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](/Images/OutliningIndicators/ContractedBlock.gif) {
int t;
scanf("%d",&t);
while(t--)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
memset(f,0,sizeof(f));
f[0][0]=1;
scanf("%d%d",&n,&m);
int i, j;
for(i=0;i<n;i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
scanf("%d%d%d",&a[i],&b[i],&c[i]);
}
DP();
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
int count=0;
for(i=0;i<=m;i++)
for(j=0;j<=m;j++)
if(f[i][j]==1)
count++;
![](/Images/OutliningIndicators/InBlock.gif)
printf("%d\n",count);
}
return 0;
}
|
|
|